第一个线程使用:
Master master = entityManager.find(Master.class, "MASTER", LockModeType.PESSIMISTIC_WRITE);
根据我的理解,如果另一个线程试图执行相同的语句,它将挂起,直到超时,然后抛出PessimisticLockingException或类似的。
然而我的另一个线程似乎永远在尝试。我不明白为什么。在启动过程中,我清楚地看到了这一点:
[EL Finest]: 2014-09-03 14:05:51.441--ServerSession(800990938)--Thread(Thread[main,5,main])--property=javax.persistence.lock.timeout; value=1
所以它似乎应该配置为很快超时,但它永远不会超时。但是当第一个线程提交时它会立即继续,所以它的行为就像超时被设置为永远...
这是挂起的查询的日志:
[EL Finest]: 2014-09-03 14:05:52.124--UnitOfWork(189021365)--Thread(Thread[@Asynchronous classpath.ear - 1,5,main])--track pessimistic locked object com.kildeen.ref.domain.Master@42243b6 with UnitOfWork 189 021 365
//TABLE LOCKED BY FIRST THREAD
// lETS DO IT AGAIN IN ANOTHER THREAD
[EL Finer]: 2014-09-03 14:05:55.101--ServerSession(800990938)--Thread(Thread[main,5,main])--client acquired: 1749988512
[EL Finer]: 2014-09-03 14:05:55.102--UnitOfWork(430231018)--Thread(Thread[main,5,main])--TX binding to tx mgr, status=STATUS_ACTIVE
[EL Finer]: 2014-09-03 14:05:55.102--ClientSession(1749988512)--Thread(Thread[main,5,main])--acquire unit of work: 430231018
[EL Finest]: 2014-09-03 14:05:55.102--UnitOfWork(430231018)--Thread(Thread[main,5,main])--Execute query ReadObjectQuery(name="readObject" referenceClass=Master sql="SELECT ID, TESTPROPERTY FROM mp_master WHERE (ID = ?)")
[EL Finer]: 2014-09-03 14:05:55.102--ClientSession(1749988512)--Thread(Thread[main,5,main])--TX beginTransaction, status=STATUS_ACTIVE
[EL Finest]: 2014-09-03 14:05:55.102--ServerSession(800990938)--Connection(1844179384)--Thread(Thread[main,5,main])--Connection acquired from connection pool [default].
[EL Finest]: 2014-09-03 14:05:55.102--ClientSession(1749988512)--Thread(Thread[main,5,main])--reconnecting to external connection pool
[EL Fine]: 2014-09-03 14:05:55.102--ClientSession(1749988512)--Connection(1575043618)--Thread(Thread[main,5,main])--SELECT ID, TESTPROPERTY FROM mp_master WHERE (ID = ?) FOR UPDATE
bind => [MASTER]
之后它陷入僵局......
将TomEE 1.7与Eclipselink 2.4.2一起使用
答案 0 :(得分:0)
切换到openjpa,它有更好的日志记录:
<openjpa-2.4.0-nonfinal-1598334-r422266:1599166 fatal general error> org.apache.openjpa.persistence.PersistenceException: The database dictionary in use ("class org.apache.openjpa.jdbc.sql.HSQLDictionary") reports that it does not have feature "SupportsSelectForUpdate". This feature is needed to complete the current operation. To force OpenJPA to try to use the feature anyway, set the following property:
openjpa.jdbc.DBDictionary: SupportsSelectForUpdate=<value>
原来它适用于postgres