I've attached a simple test which creates an object then kicks off several threads which each try to update the object. I'm using a pessimistic lock with timeout as follows:
Map<String,Object> properties = new HashMap<String,Object>(); properties.put("javax.persistence.lock.timeout", 5000); MyEntity loaded = em.find(MyEntity.class, 1, LockModeType.PESSIMISTIC_WRITE, properties);
One thread manages to do its update but the others remain blocked (for longer than 5000ms at least - I killed the test after a min or so).
If I set the timeout to less than 1000ms the blocked threads get released at the correct time but thrown a LockTimeoutException implying that the first lock wasn't released on the first commit. Anything over 1000ms causes the deadlock.