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