数据库连接在Jboss AS中关闭

时间:2014-01-15 12:08:57

标签: java hibernate java-ee jboss

我有一个在JBoss Application Server后面运行的应用程序。客户端通过服务器处理数据库操作。 EJB bean使用实体管理器处理数据库操作。

一段时间后,我看到数据库连接自动关闭。然后客户端无法从服务器请求任何内容。每个请求都会抛出异常。我发给你例外的起点。也许数据库连接有一段时间。但客户不是一个闲置的过程。它是一个模拟器,始终从服务器请求数据并将新数据发送到持久性服务器。

这里有例外

2014-01-14 20:37:35,764 INFO  [org.jboss.ejb3.async.impl.interceptor.AsynchronousClientInterceptor] (Thread-356 (group:HornetQ-client-global-threads-1610282042)) OID: null
2014-01-14 20:37:39,161 INFO  [org.jboss.ejb3.async.impl.interceptor.AsynchronousClientInterceptor] (Thread-356 (group:HornetQ-client-global-threads-1610282042)) OID: null
2014-01-14 20:38:12,572 INFO  [org.jboss.ejb3.async.impl.interceptor.AsynchronousClientInterceptor] (Thread-337 (group:HornetQ-client-global-threads-1610282042)) OID: null
2014-01-14 20:39:00,949 WARN  [com.arjuna.ats.arjuna] (Transaction Reaper) ARJUNA-12117 TransactionReaper::check timeout for TX 0:ffffc0a80127:126a:52d5345b:16fe4b in state  RUN
2014-01-14 20:39:00,950 WARN  [com.arjuna.ats.arjuna] (Transaction Reaper Worker 0) ARJUNA-12095 Abort of action id 0:ffffc0a80127:126a:52d5345b:16fe4b invoked while multiple threads active within it.
2014-01-14 20:39:00,950 WARN  [com.arjuna.ats.arjuna] (Transaction Reaper Worker 0) ARJUNA-12108 CheckedAction::check - atomic action 0:ffffc0a80127:126a:52d5345b:16fe4b aborting with 1 threads active!
2014-01-14 20:39:03,977 WARN  [com.arjuna.ats.arjuna] (Transaction Reaper) ARJUNA-12117 TransactionReaper::check timeout for TX 0:ffffc0a80127:126a:52d5345b:16fe4b in state  CANCEL
2014-01-14 20:39:03,979 ERROR [org.hibernate.event.def.AbstractFlushingEventListener] (pool-4-thread-9) Could not synchronize database state with session: org.hibernate.SessionException: Session is closed!
        at org.hibernate.impl.AbstractSessionImpl.errorIfClosed(AbstractSessionImpl.java:72) [:3.6.0.Final]
        at org.hibernate.impl.SessionImpl.getBatcher(SessionImpl.java:305) [:3.6.0.Final]
        at org.hibernate.persister.collection.AbstractCollectionPersister.recreate(AbstractCollectionPersister.java:1217) [:3.6.0.Final]
        at org.hibernate.action.CollectionRecreateAction.execute(CollectionRecreateAction.java:58) [:3.6.0.Final]
        at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:273) [:3.6.0.Final]
        at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:265) [:3.6.0.Final]
        at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:188) [:3.6.0.Final]
        at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321) [:3.6.0.Final]
        at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:51) [:3.6.0.Final]
        at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1216) [:3.6.0.Final]
        at org.hibernate.ejb.AbstractEntityManagerImpl.flush(AbstractEntityManagerImpl.java:795) [:3.6.0.Final]
        at org.jboss.jpa.impl.tx.TransactionScopedEntityManager.flush(TransactionScopedEntityManager.java:235) [:2.0.0]
        at com.siemens.siguard.simulation.ejb.SimulationResultGraphPersitenceBean.persistGraph(SimulationResultGraphPersitenceBean.java:32) [:]
        at sun.reflect.GeneratedMethodAccessor515.invoke(Unknown Source) [:1.6.0_25]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) [:1.6.0_25]
        at java.lang.reflect.Method.invoke(Method.java:597) [:1.6.0_25]
        at org.jboss.aop.joinpoint.MethodInvocation.invokeTarget(MethodInvocation.java:122) [jboss-aop.jar:2.2.1.GA]
        at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:111) [jboss-aop.jar:2.2.1.GA]
        at org.jboss.ejb3.interceptors.container.ContainerMethodInvocationWrapper.invokeNext(ContainerMethodInvocationWrapper.java:72) [:1.1.3]
        at org.jboss.ejb3.interceptors.aop.InterceptorSequencer.invoke(InterceptorSequencer.java:76) [:1.1.3]
        at org.jboss.ejb3.interceptors.aop.InterceptorSequencer.aroundInvoke(InterceptorSequencer.java:62) [:1.1.3]
        at sun.reflect.GeneratedMethodAccessor377.invoke(Unknown Source) [:1.6.0_25]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) [:1.6.0_25]
        at java.lang.reflect.Method.invoke(Method.java:597) [:1.6.0_25]
        at org.jboss.aop.advice.PerJoinpointAdvice.invoke(PerJoinpointAdvice.java:174) [jboss-aop.jar:2.2.1.GA]
        at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102) [jboss-aop.jar:2.2.1.GA]
        at org.jboss.ejb3.interceptors.aop.InvocationContextInterceptor.fillMethod(InvocationContextInterceptor.java:74) [:1.1.3]
        at org.jboss.aop.advice.org.jboss.ejb3.interceptors.aop.InvocationContextInterceptor_z_fillMethod_500571876.invoke(InvocationContextInterceptor_z_fillMethod_500571876.java) [:]
        at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102) [jboss-aop.jar:2.2.1.GA]
        at org.jboss.ejb3.interceptors.aop.InvocationContextInterceptor.setup(InvocationContextInterceptor.java:90) [:1.1.3]
        at org.jboss.aop.advice.org.jboss.ejb3.interceptors.aop.InvocationContextInterceptor_z_setup_500571876.invoke(InvocationContextInterceptor_z_setup_500571876.java) [:]
        at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102) [jboss-aop.jar:2.2.1.GA]
        at org.jboss.ejb3.async.impl.interceptor.AsynchronousServerInterceptor.invoke(AsynchronousServerInterceptor.java:128) [:1.7.17]
        at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102) [jboss-aop.jar:2.2.1.GA]
        at org.jboss.ejb3.connectionmanager.CachedConnectionInterceptor.invoke(CachedConnectionInterceptor.java:62) [:1.7.17]
        at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102) [jboss-aop.jar:2.2.1.GA]
        at org.jboss.ejb3.entity.TransactionScopedEntityManagerInterceptor.invoke(TransactionScopedEntityManagerInterceptor.java:56) [:1.7.17]
        at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102) [jboss-aop.jar:2.2.1.GA]
        at org.jboss.ejb3.AllowedOperationsInterceptor.invoke(AllowedOperationsInterceptor.java:47) [:1.7.17]
        at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102) [jboss-aop.jar:2.2.1.GA]
        at org.jboss.ejb3.tx.NullInterceptor.invoke(NullInterceptor.java:42) [:1.0.3]
        at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102) [jboss-aop.jar:2.2.1.GA]
        at org.jboss.ejb3.stateless.StatelessInstanceInterceptor.invoke(StatelessInstanceInterceptor.java:68) [:1.7.17]
        at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102) [jboss-aop.jar:2.2.1.GA]
        at org.jboss.ejb3.core.context.SessionInvocationContextAdapter.proceed(SessionInvocationContextAdapter.java:95) [:1.7.17]
        at org.jboss.ejb3.tx2.impl.CMTTxInterceptor.invokeInOurTx(CMTTxInterceptor.java:247) [:0.0.1]
        at org.jboss.ejb3.tx2.impl.CMTTxInterceptor.requiresNew(CMTTxInterceptor.java:392) [:0.0.1]
        at org.jboss.ejb3.tx2.impl.CMTTxInterceptor.invoke(CMTTxInterceptor.java:211) [:0.0.1]
        at org.jboss.ejb3.tx2.aop.CMTTxInterceptorWrapper.invoke(CMTTxInterceptorWrapper.java:52) [:0.0.1]
        at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102) [jboss-aop.jar:2.2.1.GA]
        at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:76) [:1.0.0.GA]
        at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102) [jboss-aop.jar:2.2.1.GA]
        at org.jboss.ejb3.tx.NullInterceptor.invoke(NullInterceptor.java:42) [:1.0.3]
        at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102) [jboss-aop.jar:2.2.1.GA]
        at org.jboss.ejb3.security.Ejb3AuthenticationInterceptorv2.invoke(Ejb3AuthenticationInterceptorv2.java:182) [:1.7.17]
        at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102) [jboss-aop.jar:2.2.1.GA]
        at org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:41) [:1.7.17]
        at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102) [jboss-aop.jar:2.2.1.GA]
        at org.jboss.ejb3.BlockContainerShutdownInterceptor.invoke(BlockContainerShutdownInterceptor.java:67) [:1.7.17]
        at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102) [jboss-aop.jar:2.2.1.GA]
        at org.jboss.ejb3.core.context.CurrentInvocationContextInterceptor.invoke(CurrentInvocationContextInterceptor.java:47) [:1.7.17]
        at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102) [jboss-aop.jar:2.2.1.GA]
        at org.jboss.aspects.currentinvocation.CurrentInvocationInterceptor.invoke(CurrentInvocationInterceptor.java:67) [:1.0.1]
        at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102) [jboss-aop.jar:2.2.1.GA]
        at org.jboss.ejb3.interceptor.EJB3TCCLInterceptor.invoke(EJB3TCCLInterceptor.java:86) [:1.7.17]
        at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102) [jboss-aop.jar:2.2.1.GA]
        at org.jboss.ejb3.session.SessionSpecContainer.invoke(SessionSpecContainer.java:323) [:1.7.17]
        at org.jboss.ejb3.session.SessionSpecContainer.invoke(SessionSpecContainer.java:156) [:1.7.17]
        at org.jboss.ejb3.session.SessionSpecContainer$AsyncInvocationTask.proceed(SessionSpecContainer.java:226) [:1.7.17]
        at org.jboss.ejb3.async.spi.AsyncInvocationTaskBase.call(AsyncInvocationTaskBase.java:90) [:1.0.0-alpha-9]
        at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303) [:1.6.0_25]
        at java.util.concurrent.FutureTask.run(FutureTask.java:138) [:1.6.0_25]
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441) [:1.6.0_25]
        at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303) [:1.6.0_25]
        at java.util.concurrent.FutureTask.run(FutureTask.java:138) [:1.6.0_25]
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:98) [:1.6.0_25]
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:206) [:1.6.0_25]
        at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) [:1.6.0_25]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) [:1.6.0_25]
        at java.lang.Thread.run(Thread.java:662) [:1.6.0_25]

这是用日志写的java函数。@异步注释会导致这个问题吗?

@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
@Asynchronous
public void persistGraph(ResultGraph graph)  {
    try {
        ResultGraphService service = new ResultGraphService(em);
        service.create(graph);
        em.flush();
    } catch (Exception ex) {
        throw new Exception("Error persisting graph", ex);
    }
}

1 个答案:

答案 0 :(得分:1)

您可能遇到两个问题,第一个问题是您的事务未在JBoss事务协调器(ARJUNA)允许的超时期限内提交。

但是,如果您的交易只是长期运行,那么这个建议可能有所帮助。查看您的JBoss安装文件(在Linux上,它将类似于非集群环境中的/etc/jbossas/standalone/standalone.xml)并查找此部分:

    <subsystem xmlns="urn:jboss:domain:transactions:1.3">
        <core-environment>
            <process-id>
                <uuid/>
            </process-id>
        </core-environment>
        <recovery-environment socket-binding="txn-recovery-environment" status-socket-binding="txn-status-manager"/>
        <coordinator-environment default-timeout="300"/>
    </subsystem>

注意<coordinator-environment>的default-timeout属性。默认情况下为300秒。现在,5分钟应该有足够的时间来运行事务,但是在长时间运行的繁重批处理中,可能会超出此限制。如果您怀疑这是您的问题,请增加此参数(以秒为单位),然后退回JBoss(您也可以通过JBoss管理控制台执行此操作,但我发现在开发过程中,更容易修改独立版本。 xml和反弹JBoss)。

HTH