I\'m trying to implement some kind of semaphores for cron jobs that runs in different JBoss nodes. I\'m trying to use the database (Oracle 11g) as a locking mechanism using
I can confirm Ricardos observation. I have several Lock-Modes tested with a H2-Database, and all worked as expected. Neither of the pessimistic Lock-Modes worked correctly in combination with an Oracle database. I did not try optimistic locking, but it's amazing that there's a lockmode that doesn't work with the top dog at all.
Set locking mode to PESSIMISTIC_READ, because you need that second server knew about changes of first server before changing data.
Finally i managed to make it work but with some modiffications. The idea is to use LockModeType.PESSIMISTIC_FORCE_INCREMENT instead of PESSIMISTIC_WRITE. Using this lock mode the Cron Jobs behave as follows:
This solution has various counterparts: