获取事务已在另一个线程exception中回滚

所以我在Wildfly 10 Application Server中配置了2个xa-datsource,我使用的是Hibernate ORM 5.2.9。 DB是Postgres 9.6

在我的应用程序中,我有一个EJB,它有2个嵌套for循环,我必须在嵌套循环的每次迭代中从表中读取数据。 但过了一段时间我才得到这个例外

javax.ejb.EJBTransactionRolledbackException:org.hibernate.HibernateException:事务在另一个线程中回滚!

我不明白为什么会这样。 我有一个小概念validation应用程序,它使用JDBC连接到数据库,一切正常。

编辑这是我提到的exception抛出后的堆栈跟踪:

12:39:07,319 WARN [com.arjuna.ats.arjuna](默认任务-7)ARJUNA012077:Abort调用已经中止的primefaces动作0:ffffac280184:2edc54df:598adfb2:27f 12:39:07,320 ERROR [org.jboss。 as.ejb3.invocation](默认任务-7)WFLYEJB0034:对于方法public void com.actuariado.smartsolve.services.api.calculation.CalculationResource.calculateFinancial(org.jboss.resteasy.plugins),组件ejb / calculationResource上的EJB调用失败。 providers.multipart.MultipartFormDataInput)抛出com.actuariado.smartsolve.exceptions.AppException:javax.ejb.EJBTransactionRolledbackException:事务在org.jboss.as.ejb3.tx.CMTTxInterceptor.handleEndTransactionException(CMTTxInterceptor.java:137)回滚到org。位于org.jboss.as.ejb3.tx的org.jboss.as.ejb3.tx.CMTTxInterceptor.invokeInOurTx(CMTTxInterceptor.java:279)的jboss.as.ejb3.tx.CMTTxInterceptor.endTransaction(CMTTxInterceptor.java:117)。位于org.jboss.as.ejb3.tx.CMTTxInterceptor.processInvoca的CMTTxInterceptor.required(CMTTxInterceptor.java:327) org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)org.jboss.as.ejb3.component.interceptors.CurrentInvocationContextInterceptor.processInvocation(CurrentInvocationContextInterceptor.java:41)at org(CMTTxInterceptor.java:239) .jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)org.jboss.as.ejb3.component.invocationmetrics.WaitTimeInterceptor.processInvocation(WaitTimeInterceptor.java:47)at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext) .java:340)org.jboss.as.ejb3.security.SecurityContextInterceptor.processInvocation(SecurityContextInterceptor.java:100)org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)org.jboss.as。位于org.jboss.as.ejb3.component.interceptors.ShutDownInterceptorFactory $ 1.proces的org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)的ejb3.deployment.processors.StartupAwaitInterceptor.processInvocation(StartupAwaitInterceptor.java:22) org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)中的orInv.jboss.as.ejb3.component.interceptors.LoggingInterceptor.processInvocation(LoggingInterceptor.java:67)中的sInvocation(ShutDownInterceptorFactory.java:64)位于org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java)的org.jboss.as.ee.component.NamespaceContextInterceptor.processInvocation(NamespaceContextInterceptor.java:50)中的.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340) :340)org.jboss.as.ejb3.component.interceptors.AdditionalSetupInterceptor.processInvocation(AdditionalSetupInterceptor.java:54)org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)org.jboss.invocation。 org.wboss.invocation.InterceptorContext.run上的org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)中的ContextClassLoaderInterceptor.processInvocation(ContextClassLoaderInterceptor.java:64)org.wildfly.secu上的org.jboss.invocation.InterceptorContext.run(InterceptorContext.java:356) org.jboss.invocation.AccessCheckingInterceptor.processInvocation(AccessCheckingInterceptor.java:61)中的org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)中的rity.manager.WildFlySecurityManager.doChecked(WildFlySecurityManager.java:636) .jboss.invocation.InterceptorContext.run(InterceptorContext.java:356)位于org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)的org.jboss.invocation.PrivilegedWithCombinerInterceptor.processInvocation(PrivilegedWithCombinerInterceptor.java:80) org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:61)位于org.jboss.as.ee.component的org.jboss.as.ee.component.ViewService $ View.invoke(ViewService.java:198)。位于org.jboss的org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:340)org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:61)中的ViewDescription $ 1.processInvocation(ViewDescription.java:185)。 as.ee.component.ProxyInvoc ationHandler.invoke(ProxyInvocationHandler.java:73)位于sun.reflect的sun.reflect.NativeMethodAccessorImpl.invoke0(本地方法)中的com.actuariado.smartsolve.services.api.calculation.CalculationResource $$$ view200.calculateFinancial(未知来源) .nativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)位于org.jboss.resteasy的java.lang.reflect.Method.invoke(Method.java:498)的sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)。 core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:139)org.jboss.resteasy.core.ResourceMethodInvoker.invokeOnTarget(ResourceMethodInvoker.java:295)org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:249) org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:236)org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:402)org.jboss.resteasy.core.SynchronousDispatcher.invoke (SynchronousDispatcher.java:209)org.jboss.r 位于org.jboss.resteasy.plugins的org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:56)中的esteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:221)。位于io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:85)的javax.servlet.http.HttpServlet.service(HttpServlet.java:790)中的server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:51)在io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62)处于org.wildfly.extension.undertow.security的io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36) .SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(S) SLInformationAssociationHandler.java:131)在io.undertow的io.undertow.servlet.server.sev.Avheler.etle上,io.undertow.server.handler.PredicateHandler.handleRequest(PredicateHandler.java:43)的io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:57) .security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:46)at io.undertow.servlet.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:64)at io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler) .java:60)在io.undertow的io.undertow.servler.security.security.CallAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:77)处的io.undertow.security.handlers.NotificationReceiverHandler.handleRequest(NotificationReceiverHandler.java:50)。 security.handlers.AbstractSecurityContextAssociationHandler.handleRequest(AbstractSecurityContextAs sociationHandler.java:43)ato.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61)at io .undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler) .java:292)在io.undertow的io.undertow.servlet.handlers.ServletInitialHandler.access $ 100(ServletInitialHandler.java:81)io.undertow.servlet.handlers.ServletInitialHandler $ 2.call(ServletInitialHandler.java:138)。 servlet.handlers.ServletInitialHandler $ 2.call(ServletInitialHandler.java:135)at io.undertow.servlet.core.ServletRequestContextThreadSetupAction $ 1.call(ServletRequestContextThreadSetupAction.java:48)at io.undertow.servlet.core.ContextClassLoaderSetupAction $ 1.call(ContextClassLoaderSetup) Action.java:43)io.undertow.servlet.api.LegacyThreadSetupActionWrapper $ 1.call(LegacyThreadSetupActionWrapper.java:44)at io.undertow.servall.api.LegacyThreadSetupActionWrapper $ 1.call(LegacyThreadSetupActionWrapper.java:44)at io.undertow .servlet.api.LegacyThreadSetupActionWrapper $ 1.call(LegacyThreadSetupActionWrapper.java:44)at io.undertow.servlet.api.LegacyThreadSetupActionWrapper $ 1.call(LegacyThreadSetupActionWrapper.java:44)at io.undertow.servlet.api.LegacyThreadSetupActionWrapper $ 1.call( LegacyThreadSetupActionWrapper.java:44)在io.undertow的io.undertow.servlet.api.LegacyThreadSetupActionWrapper $ 1.call(LegacyThreadSetupActionWrapper.java:44)中的io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:272)。 servlet.handlers.ServletInitialHandler.access $ 000(ServletInitialHandler.java:81)at io.undertow.servlet.handler.ServletInitialHandler $ 1.handleRequest(ServletInitialHandler.java:104)at io.undertow.server.Connectors.executeRootHandler(Co nnectors.java:202)at io.undertow.server.HttpServerExchange $ 1.run(HttpServerExchange.java:805)at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)at java.util.concurrent.ThreadPoolExecutor $ java.lang.Thread.run上的Worker.run(ThreadPoolExecutor.java:617)(Thread.java:745)引起:javax.transaction.RollbackException:WFLYEJB0447:事务’TransactionImple ‘已经回滚到org.jboss.as.ejb3.tx.CMTTxInterceptor.endTransaction(CMTTxInterceptor.java:98)… 88更多

所以我想我弄清楚发生了什么。 看起来,当调用我的EJB方法时,Container会创建一个全局JTA事务,或类似的事务,它的超时时间为5分钟(默认来自Wildfly)。 由于我的业务逻辑(嵌套循环)花费的时间超过了处理时间,因此当我尝试再次访问数据库时,事务会超时并抛出该exception。