• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to modify the username only once

 
saikrishna cinux
Ranch Hand
Posts: 689
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Sylven Yip
Ranch Hand
Posts: 42
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 689
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13411
Firefox Browser Redhat VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It depends on how you're storing the username.

Where are you storing it?
In a database?
 
saikrishna cinux
Ranch Hand
Posts: 689
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10336
Eclipse IDE Hibernate Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
saikrishna cinux
Ranch Hand
Posts: 689
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10336
Eclipse IDE Hibernate Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 689
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
author & internet detective
Marshal
Posts: 33684
316
Eclipse IDE Java VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic