This week's book giveaway is in the OCAJP forum.
We're giving away four copies of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) and have Khalid A Mughal & Rolf W Rasmussen on-line!
See this thread for details.
Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hibernate locking a row for read update

 
P Rao
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1682
7
Android IntelliJ IDE Linux Mac OS X Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic