This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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 Murach's Java Servlets and JSP this week in the Servlets 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: 1646
    
    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]
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Hibernate locking a row for read update
 
Similar Threads
Add a row to table and update data
SCJD test locking concept for Bogitt & Scarper
Hibernate 2: locking a row
Few Question About Threads
Thread in clustered environment