| Author |
how to modify the username only once
|
saikrishna cinux
Ranch Hand
Joined: Apr 16, 2005
Posts: 689
|
|
Hi, here is a simple scenerio i am explaining When i am trying to update the user naem at particular instance of time the other end user should not able to update the username at same time. how can do this? using synchronized? using single thread model? or using singleton? Please guide me in this issue thanks in advance sai
|
A = HARDWORK B = LUCK/FATE If C=(A+B) then C=SUCCESSFUL IN LIFE else C=FAILURE IN LIFE
SCJP 1.4
|
 |
Ben Souther
Sheriff
Joined: Dec 11, 2004
Posts: 13410
|
|
You haven't given us any details. What username? Where are you storing this username? What type of update do you want to do with it.
|
Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
|
 |
Sylven Yip
Ranch Hand
Joined: Aug 30, 2007
Posts: 42
|
|
remember,never use single thread model. i don't clear about your usage of "username". often,username is a variable that every session should one each,they don't disturb each other. but,if "username" is a shared variable(i guess),you must use synchronized block.(don't synchronize the whole method). in particular,choose the right synchronized object.
|
 |
saikrishna cinux
Ranch Hand
Joined: Apr 16, 2005
Posts: 689
|
|
Originally posted by Sylven Yip: remember,never use single thread model. i don't clear about your usage of "username". often,username is a variable that every session should one each,they don't disturb each other. but,if "username" is a shared variable(i guess),you must use synchronized block.(don't synchronize the whole method). in particular,choose the right synchronized object.
Hi Ben,Yip After loggining in by particular user "xyz" i want to change some other user name called "abc" but at the same point of time no one should able to change the user name "abc". i know pretty well that i should nto use synchronized or singleThread model for this? Indeed !! can i use singleton?
|
 |
Ben Souther
Sheriff
Joined: Dec 11, 2004
Posts: 13410
|
|
It depends on how you're storing the username. Where are you storing it? In a database?
|
 |
saikrishna cinux
Ranch Hand
Joined: Apr 16, 2005
Posts: 689
|
|
Originally posted by Ben Souther: It depends on how you're storing the username. Where are you storing it? In a database?
Yes, ofcourse.
|
 |
Paul Sturrock
Bartender
Joined: Apr 14, 2004
Posts: 10336
|
|
You can use a locking strategy. Google for "pessimistic locking" and "optimistic locking". Once you've leared what these are you can think about which best suits your situation. Generally pessimistic locking is not a good idea, since it creates a bottleneck. In most multiuser applciations optimistic locking is fine.
|
JavaRanch FAQ HowToAskQuestionsOnJavaRanch
|
 |
saikrishna cinux
Ranch Hand
Joined: Apr 16, 2005
Posts: 689
|
|
Originally posted by Paul Sturrock: You can use a locking strategy. Google for "pessimistic locking" and "optimistic locking". Once you've leared what these are you can think about which best suits your situation. Generally pessimistic locking is not a good idea, since it creates a bottleneck. In most multiuser applciations optimistic locking is fine.
Locking means again it's a kind of Synchronized code.Means it kills time
|
 |
Paul Sturrock
Bartender
Joined: Apr 14, 2004
Posts: 10336
|
|
Locking means again it's a kind of Synchronized code.Means it kills time
Not quite right. Pessimistic locking is a bottleneck, like I say, but is also not likely to be a strategy that applies in this case. Have a google for these two terms and you'll see that neither require any synchronized block, single threaded access to the database, or singleton patterns.
|
 |
saikrishna cinux
Ranch Hand
Joined: Apr 16, 2005
Posts: 689
|
|
Originally posted by Paul Sturrock: Not quite right. Pessimistic locking is a bottleneck, like I say, but is also not likely to be a strategy that applies in this case. Have a google for these two terms and you'll see that neither require any synchronized block, single threaded access to the database, or singleton patterns.
Pessimistic locking is powerful because we can lock certain record or some set of records avoiding updating by some other clients. where as the optimistic lock needs our own private cache for locking the client data. My personal opinion wise i want to go thru optimistic locking mechanism :-) because I dont know much about oracle databse side. so can you please give me further suggestion for implementying the optimistic locking mechanism. Paul, Anways I am Thankful to you for giving an innovative suggestion in the right time. :thumb: Thanks, and please guide me ...
|
 |
Jeanne Boyarsky
internet detective
Marshal
Joined: May 26, 2003
Posts: 26200
|
|
Saikrishna, One approach is to add an id or timestamp column to the table. When the user retrieves a row, they get this id. When they go to update the table, they make sure the id is still the same and then update the id. If the ids match, nobody else has changed the record. If not, they need to get the record again and start over. This approach is for when you have multiple columns. If you just have one column, the database takes care of it for you.
|
[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
|
 |
 |
|
|
subject: how to modify the username only once
|
|
|