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,