gpt4 book ai didi

java - Wildfly 8.0.0.Final + EntityManager + PostgreSQL - 事务空闲

转载 作者:行者123 更新时间:2023-11-29 13:28:33 28 4
gpt4 key购买 nike

我在 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);
}
}

write 和 update 方法都是并行调用的,因为它们是直接从另一个处理 HTTP 请求的类调用的:

@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(entity) 上。

在 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”。我在类路径上也有 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 重现该问题。

关于java - Wildfly 8.0.0.Final + EntityManager + PostgreSQL - 事务空闲,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29036885/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com