File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes EJB and other Java EE Technologies and the fly likes concurrent update issue Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "concurrent update issue" Watch "concurrent update issue" New topic
Author

concurrent update issue

VenuGopal Thati
Greenhorn

Joined: Feb 05, 2010
Posts: 4
Hi,

I have a table with optimistic versioning implemented using hibernate. one row in this table can be updated by more than one transaction at the same time and this update method is in stateless session bean. Issue here is when users are working on application at peak time, three to four transactions trying to update same row and database allows update for first transaction and other transactions getting versioning error (This works as per the implementation). Because of this user's operations are getting delayed and they have to repeat same process until database allows update.

Is there anyway to allow updates from multiple transactions with optimistic versioning in place ? please suggest.

Thanks in Advance.
Jayesh A Lalwani
Bartender

Joined: Jan 17, 2008
Posts: 2321
    
  28

Yes, don;t do optimistic locking. However, you might run into problem of one transaction overwriting another transaction's changes

VenuGopal Thati
Greenhorn

Joined: Feb 05, 2010
Posts: 4
Jayesh,

If I don't do optimistic locking data will be corrupted. Thanks for your response.
Jayesh A Lalwani
Bartender

Joined: Jan 17, 2008
Posts: 2321
    
  28

Yes, exactly. THe only way to prevent data corruption is to prevent 2 transaction from updating a record concurrently. Optimistic locking is the mechanism that you use. If you allow 2 transactions to update the record at the same time, you will always have the possibility of data corruption, no matter what you do



Lucas Smith
Ranch Hand

Joined: Apr 20, 2009
Posts: 804
    
    1

Optimistic locking is used when it is unlikely that the same row is going to be modified by many transactions concurrently. I think that you should use pessimistic locking instead. Just get the entity with LockMode.PESSIMISTIC_WRITE and other transactions will have to wait for the lock release.


SCJP6, SCWCD5, OCE:EJBD6.
BLOG: http://leakfromjavaheap.blogspot.com
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: concurrent update issue