0 Replies Latest reply on Mar 31, 2005 4:27 PM by fredatwork

    Acquiring a lock on a row

    fredatwork Newbie


      I'm looking for a way to try to lock on given database row in order to implement some locking mechanism for the management of my transactions.

      For this purpose, the immediate thought is to use the following class level XDoclet tag on my entity bean :


      that permits to have select statements being generated with the SELECT ... FOR UPDATE syntax, and thus generate a lock until the current transaction is over.

      The problem is that there is (as far as I know) no way to back off from an attempt to acquire such a lock that is already held, or to give up after waiting for a specified period of time, or to cancel a lock attempt after an interrupt.

      The Java 5.0 SDK introduces a new java.util.concurrent package for concurrency matters. The ReentrantLock class has a tryLock() method