File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

database row locking and update

 
Frank Sikuluzu
Ranch Hand
Posts: 116
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
when u have multiple users trying to update a record, how do u handle it -

1. do u handle it by writing codes (multiple threading) ?
2. or do u handle it from the database side, ie.e force the database to do locking ?

or do u do both 1) and 2) ?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64171
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Frank,

JavaRanch is a community of people from all over the world, many of who are not native English speakers. While using abbreviations like "u" instead of spelling out "you" is convenient when text messaging your friends on a cell phone or in a chat room, it presents an extra challenge to those that are already struggling with English. Additionally, such shortcuts may confound automated translation tools that patrons of the Ranch may be making use of.

I would like to ask for your help in making the content of JavaRanch a little easier to read for everybody that visits here by not using such abbreviations.

thanks,
bear
Forum Bartender
 
Julian Kennedy
Ranch Hand
Posts: 823
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Frank,

If I take your question literally the answer is neither. Perhaps you could post what you want to achieve through this locking and describe a short scenario? That way we can advise you on the best approach. You certainly shouldn't be considering thread synchronisation in Java to achieve this.

Jules
 
Frank Sikuluzu
Ranch Hand
Posts: 116
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The scenario is simple --- The web tier offers customers chance to update some database information. Since it is possible that multiple users are online to update the database, I want to make sure that the database table (or row record) is locked when one user is updating, and that user should unlock it when he finishes. How to achieve this effect ? please provide some details. thanks,
 
Julian Kennedy
Ranch Hand
Posts: 823
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you select the data for the customer to update into the web tier first? That is, could two users be looking at/updating the same record at the same time? Is that what you're talking about? If so the optimum approach depends on how frequently you expect to get a collision. Frequent collisions require a pessimistic locking strategy; occasional/infrequent/rare collisions suggest an optimistic locking strategy would be most appropriate.

Jules
 
Frank Sikuluzu
Ranch Hand
Posts: 116
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Julian Kennedy:
Do you select the data for the customer to update into the web tier first? That is, could two users be looking at/updating the same record at the same time? Is that what you're talking about? If so the optimum approach depends on how frequently you expect to get a collision. Frequent collisions require a pessimistic locking strategy; occasional/infrequent/rare collisions suggest an optimistic locking strategy would be most appropriate.

Jules


julian, I feel you are the one who can give me the answers. Please, please continue on describing the details of optimistic and pessimistic locking methods. I want to know ---

1. what kind coding I need to do ?
2. what kind special SQL or database work I need to do ?

thanks
 
Julian Kennedy
Ranch Hand
Posts: 823
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Frank,

Of course I can give you the answers, but I'm not going to do the work for you. That's your job. If you answer my questions then maybe I can help further. I suggest you also search the web to help you to better understand the terms I've mentioned. If you run into trouble trying to implement one of the locking strategies or you feel you need further pointers I'd be happy to help.

Jules
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic