aspose file tools*
The moose likes Object Relational Mapping and the fly likes Hibernate locking a row for read update Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Hibernate locking a row for read update" Watch "Hibernate locking a row for read update" New topic
Author

Hibernate locking a row for read update

P Rao
Greenhorn

Joined: Aug 05, 2012
Posts: 1
Hi,
I have a job processing application that will be running in a cluster, hence multiple JVMs. The Jobs will be sitting in a database and a scheduler will wake up every x seconds loads a job, has to update the row with a processing flag (so other thread will not load and process the same job).
So I added a special state field that can be "NEW", "PROCESSING" and "COMPLETED"
When the state of a job is "NEW", the job can be grabbed from the database by one of the threads and the field of that object will be set to "PROCESSING" so that other threads will not load the same job. BUT how can I ensure that in case of similtaniouse access and before the state change, 2 threads will not grab the same job. what is the best way to tackle this problem?

Thanks,
Bill Gorder
Bartender

Joined: Mar 07, 2010
Posts: 1680
    
    7

You could do this yourself but it is probably best to use a proven and tested library to handle this. I have used Quartz for this in the past and it worked well.


[How To Ask Questions][Read before you PM me]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Hibernate locking a row for read update