我使用 WebSphere 7 和 OpenJPA。
这是两个bean和persistance.xml的一部分:
<persistence-unit name="ASAP_Main">
<jta-data-source>jdbc/ASAPDB</jta-data-source>
<properties>
<property name="openjpa.Optimistic" value="false"/>
<property name="openjpa.ReadLockLevel" value="none"/>
<property name="openjpa.WriteLockLevel" value="none"/>
<property name="openjpa.LockManager" value="pessimistic(VersionCheckOnReadLock=false,VersionUpdateOnWriteLock=false)"/>
<property name="openjpa.LockTimeout" value="20000"/>
</properties>
</persistence-unit>
@PersistenceContext(unitName = "ASAP_Main")
private EntityManager em;
@MessageDriven
public class A implements MessageListener {
@EJB
private B b;
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public void onMessage(Message message) {
b.processWithLock(message.getObject());
...
}
}
@Stateless
public class B{
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public void processWithLock(Object obj){
em.lock(obj)
...
}
}
processWithLock执行后是否释放锁?