Wildfly 8.0.0.Final + EntityManager + PostgreSQL - 事务空闲
Wildfly 8.0.0.Final + EntityManager + PostgreSQL - idle in transaction
我在 Wildfly 8.0 上有以下代码 运行。0.Final:
@Stateful
public class MyJPABean<T> {
@PersistenceContext(unitName = "myUnitName")
private EntityManager em;
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public void write(T entity) {
em.persist(entity);
em.flush();
}
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public void update(T entity) {
em.merge(entity);
}
}
写入和更新方法都是并行调用的,因为它们是直接从另一个处理 HTTP 请求的 class 调用的:
@Path("api")
public class MyApiController {
private MyJPABean<MyJpaModel> jpaBean;
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public void handlePost(MyJpaModel myJpaModel) {
jpaBean.write(myJpaModel);
}
}
部分"write"方法调用成功,但有时"write"方法被多个线程并行调用时,开始挂在em.persist (实体)。
在 PostgreSQL 服务器端,我可以看到状态中的事务:"idle in transaction" 查询:"select nextval ('hibernate_sequence')" 或插入从我刚刚尝试保留的实体创建的查询。
发生此问题时,我无法再保留实体。一切都挂在 em.persist(entity) 上。要么我无法杀死 wildfly 进程,我必须用 -9 信号杀死它。
我做错了什么吗?
一段时间后(发生超时),我可以在应用程序日志中看到以下警告:
16:44:30,590 WARN [com.arjuna.ats.arjuna] (Transaction Reaper) ARJUNA012117: TransactionReaper::check timeout for TX 0:ffff7f000101:-231d9b5d:55030494:2d in state RUN
16:44:30,591 WARN [com.arjuna.ats.arjuna] (Transaction Reaper Worker 0) ARJUNA012095: Abort of action id 0:ffff7f000101:-231d9b5d:55030494:2d invoked while multiple threads active within it.
16:44:30,591 WARN [com.arjuna.ats.arjuna] (Transaction Reaper Worker 0) ARJUNA012108: CheckedAction::check - atomic action 0:ffff7f000101:-231d9b5d:55030494:2d aborting with 1 threads active!
16:44:30,598 WARN [com.arjuna.ats.arjuna] (Transaction Reaper) ARJUNA012117: TransactionReaper::check timeout for TX 0:ffff7f000101:-231d9b5d:55030494:35 in state RUN
16:44:31,090 WARN [com.arjuna.ats.arjuna] (Transaction Reaper) ARJUNA012117: TransactionReaper::check timeout for TX 0:ffff7f000101:-231d9b5d:55030494:2d in state CANCEL
16:44:31,092 WARN [com.arjuna.ats.arjuna] (Transaction Reaper) ARJUNA012378: ReaperElement appears to be wedged: com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator.afterCompletion(TwoPhaseCoordinator.java:487)
com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator.afterCompletion(TwoPhaseCoordinator.java:463)
com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator.cancel(TwoPhaseCoordinator.java:118)
com.arjuna.ats.arjuna.AtomicAction.cancel(AtomicAction.java:215)
com.arjuna.ats.arjuna.coordinator.TransactionReaper.doCancellations(TransactionReaper.java:377)
com.arjuna.ats.internal.arjuna.coordinator.ReaperWorkerThread.run(ReaperWorkerThread.java:78)
16:44:31,100 WARN [com.arjuna.ats.arjuna] (Transaction Reaper) ARJUNA012117: TransactionReaper::check timeout for TX 0:ffff7f000101:-231d9b5d:55030494:35 in state SCHEDULE_CANCEL
16:44:31,594 WARN [com.arjuna.ats.arjuna] (Transaction Reaper) ARJUNA012117: TransactionReaper::check timeout for TX 0:ffff7f000101:-231d9b5d:55030494:2d in state CANCEL_INTERRUPTED
16:44:31,595 WARN [com.arjuna.ats.arjuna] (Transaction Reaper) ARJUNA012120: TransactionReaper::check worker Thread[Transaction Reaper Worker 0,5,main] not responding to interrupt when cancelling TX 0:ffff7f000101:-231d9b5d:55030494:2d -- worker marked as zombie and TX scheduled for mark-as-rollback
16:44:31,596 WARN [com.arjuna.ats.arjuna] (Transaction Reaper Worker 1) ARJUNA012095: Abort of action id 0:ffff7f000101:-231d9b5d:55030494:35 invoked while multiple threads active within it.
16:44:31,597 WARN [com.arjuna.ats.arjuna] (Transaction Reaper) ARJUNA012110: TransactionReaper::check successfuly marked TX 0:ffff7f000101:-231d9b5d:55030494:2d as rollback only
16:44:31,597 WARN [com.arjuna.ats.arjuna] (Transaction Reaper Worker 1) ARJUNA012108: CheckedAction::check - atomic action 0:ffff7f000101:-231d9b5d:55030494:35 aborting with 1 threads active!
16:44:31,600 WARN [com.arjuna.ats.arjuna] (Transaction Reaper) ARJUNA012117: TransactionReaper::check timeout for TX 0:ffff7f000101:-231d9b5d:55030494:35 in state CANCEL
16:44:31,602 WARN [com.arjuna.ats.arjuna] (Transaction Reaper) ARJUNA012378: ReaperElement appears to be wedged: org.apache.log4j.AppenderSkeleton.doAppend(AppenderSkeleton.java:231)
作为 jdbc 驱动程序,使用 "postgresql-9.2-1004.jdbc41"。 PostgreSQL 服务器版本为“9.3”。我在 class 路径上也有 c3p0,但即使我删除了这个依赖项,问题仍然存在。
我已经使用 JAX-RS、EJB 和 JPA 准备了一个示例应用程序 - https://github.com/aparnachaudhary/prototypes/tree/master/jaxrs-db-access。
我使用 JMeter 脚本通过多线程访问 REST 端点。但我无法使用 PostgreSQL 9.3、postgresql-9.3-1103.jdbc41.jar 和 WildFly 8.1.0.Final.
重现该问题
我在 Wildfly 8.0 上有以下代码 运行。0.Final:
@Stateful
public class MyJPABean<T> {
@PersistenceContext(unitName = "myUnitName")
private EntityManager em;
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public void write(T entity) {
em.persist(entity);
em.flush();
}
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public void update(T entity) {
em.merge(entity);
}
}
写入和更新方法都是并行调用的,因为它们是直接从另一个处理 HTTP 请求的 class 调用的:
@Path("api")
public class MyApiController {
private MyJPABean<MyJpaModel> jpaBean;
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public void handlePost(MyJpaModel myJpaModel) {
jpaBean.write(myJpaModel);
}
}
部分"write"方法调用成功,但有时"write"方法被多个线程并行调用时,开始挂在em.persist (实体)。
在 PostgreSQL 服务器端,我可以看到状态中的事务:"idle in transaction" 查询:"select nextval ('hibernate_sequence')" 或插入从我刚刚尝试保留的实体创建的查询。
发生此问题时,我无法再保留实体。一切都挂在 em.persist(entity) 上。要么我无法杀死 wildfly 进程,我必须用 -9 信号杀死它。
我做错了什么吗?
一段时间后(发生超时),我可以在应用程序日志中看到以下警告:
16:44:30,590 WARN [com.arjuna.ats.arjuna] (Transaction Reaper) ARJUNA012117: TransactionReaper::check timeout for TX 0:ffff7f000101:-231d9b5d:55030494:2d in state RUN
16:44:30,591 WARN [com.arjuna.ats.arjuna] (Transaction Reaper Worker 0) ARJUNA012095: Abort of action id 0:ffff7f000101:-231d9b5d:55030494:2d invoked while multiple threads active within it.
16:44:30,591 WARN [com.arjuna.ats.arjuna] (Transaction Reaper Worker 0) ARJUNA012108: CheckedAction::check - atomic action 0:ffff7f000101:-231d9b5d:55030494:2d aborting with 1 threads active!
16:44:30,598 WARN [com.arjuna.ats.arjuna] (Transaction Reaper) ARJUNA012117: TransactionReaper::check timeout for TX 0:ffff7f000101:-231d9b5d:55030494:35 in state RUN
16:44:31,090 WARN [com.arjuna.ats.arjuna] (Transaction Reaper) ARJUNA012117: TransactionReaper::check timeout for TX 0:ffff7f000101:-231d9b5d:55030494:2d in state CANCEL
16:44:31,092 WARN [com.arjuna.ats.arjuna] (Transaction Reaper) ARJUNA012378: ReaperElement appears to be wedged: com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator.afterCompletion(TwoPhaseCoordinator.java:487)
com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator.afterCompletion(TwoPhaseCoordinator.java:463)
com.arjuna.ats.arjuna.coordinator.TwoPhaseCoordinator.cancel(TwoPhaseCoordinator.java:118)
com.arjuna.ats.arjuna.AtomicAction.cancel(AtomicAction.java:215)
com.arjuna.ats.arjuna.coordinator.TransactionReaper.doCancellations(TransactionReaper.java:377)
com.arjuna.ats.internal.arjuna.coordinator.ReaperWorkerThread.run(ReaperWorkerThread.java:78)
16:44:31,100 WARN [com.arjuna.ats.arjuna] (Transaction Reaper) ARJUNA012117: TransactionReaper::check timeout for TX 0:ffff7f000101:-231d9b5d:55030494:35 in state SCHEDULE_CANCEL
16:44:31,594 WARN [com.arjuna.ats.arjuna] (Transaction Reaper) ARJUNA012117: TransactionReaper::check timeout for TX 0:ffff7f000101:-231d9b5d:55030494:2d in state CANCEL_INTERRUPTED
16:44:31,595 WARN [com.arjuna.ats.arjuna] (Transaction Reaper) ARJUNA012120: TransactionReaper::check worker Thread[Transaction Reaper Worker 0,5,main] not responding to interrupt when cancelling TX 0:ffff7f000101:-231d9b5d:55030494:2d -- worker marked as zombie and TX scheduled for mark-as-rollback
16:44:31,596 WARN [com.arjuna.ats.arjuna] (Transaction Reaper Worker 1) ARJUNA012095: Abort of action id 0:ffff7f000101:-231d9b5d:55030494:35 invoked while multiple threads active within it.
16:44:31,597 WARN [com.arjuna.ats.arjuna] (Transaction Reaper) ARJUNA012110: TransactionReaper::check successfuly marked TX 0:ffff7f000101:-231d9b5d:55030494:2d as rollback only
16:44:31,597 WARN [com.arjuna.ats.arjuna] (Transaction Reaper Worker 1) ARJUNA012108: CheckedAction::check - atomic action 0:ffff7f000101:-231d9b5d:55030494:35 aborting with 1 threads active!
16:44:31,600 WARN [com.arjuna.ats.arjuna] (Transaction Reaper) ARJUNA012117: TransactionReaper::check timeout for TX 0:ffff7f000101:-231d9b5d:55030494:35 in state CANCEL
16:44:31,602 WARN [com.arjuna.ats.arjuna] (Transaction Reaper) ARJUNA012378: ReaperElement appears to be wedged: org.apache.log4j.AppenderSkeleton.doAppend(AppenderSkeleton.java:231)
作为 jdbc 驱动程序,使用 "postgresql-9.2-1004.jdbc41"。 PostgreSQL 服务器版本为“9.3”。我在 class 路径上也有 c3p0,但即使我删除了这个依赖项,问题仍然存在。
我已经使用 JAX-RS、EJB 和 JPA 准备了一个示例应用程序 - https://github.com/aparnachaudhary/prototypes/tree/master/jaxrs-db-access。 我使用 JMeter 脚本通过多线程访问 REST 端点。但我无法使用 PostgreSQL 9.3、postgresql-9.3-1103.jdbc41.jar 和 WildFly 8.1.0.Final.
重现该问题