I have multiple quartz workers
Each worker picks a db record (printer) and then doing some work on it (reading info from the printer over the network).
It can take up to 30 sec to 1 min to complete each job.
Back in JDBC days I would run (pseudo code)
printer = "select from printer where status=? for update"
do the work, (takes 1 min)
update the printer record.
My question is this approach with PESSIMISTIC_WRITE is ok:
public interface PrinterRepo extends CrudRepository<Printer,String>
{
@Lock(LockModeType.PESSIMISTIC_WRITE)
@Query("SELECT r FROM Printers r where r.status = :status")
Printer findOneAndLock(@Param("status")String status);
}
Then the worker:
@Transactional
public void execute(JobExecutionContext jobExecutionContext) {
Printer p = printerRepo.findOneAndLock("status");
//do the work here (30 sec to 1 min)
printerRepo.save(p);
}
For my understanding lock will be release at the end of the function annotated with @Transactional correct?
My question is what will happen to other workers?
Will they starve while waiting for findOneAndLock?
Thank you