2013-05-15 240 views
1

我正在使用Postgres数据库。有时连接会自动关闭,而与我的应用程序交互。有时甚至我没有与我的应用程序坐在理想当时也互动closed.It显示follwing excepion.My服务器日志是数据库连接自动关闭

SEVERE [org.activiti.engine.impl.jobexecutor.AcquireJobsRunnable] (Thread-101) exception during job acquisition: 

Error querying database. Cause: org.postgresql.util.PSQLException: This connection has been closed. 

The error may exist in org/activiti/db/mapping/entity/Job.xml 

The error may involve org.activiti.engine.impl.persistence.entity.JobEntity.selectNextJobsToExecute 
The error occurred while executing a query 

SQL: select  RES.*   from ACT_RU_JOB RES   LEFT OUTER JOIN ACT_RU_EXECUTION PI ON PI.ID_ = RES.PROCESS_INSTANCE_ID_  where (RES.RETR 
IES_ > 0)  and (RES.DUEDATE_ is null or RES.DUEDATE_ < ?)  and (RES.LOCK_OWNER_ is null or RES.LOCK_EXP_TIME_ < ?) and (  (RES.EXECUTION_ID_ 
is null)  or  (PI.SUSPENSION_STATE_ = 1)  )  LIMIT ? OFFSET ? 

Cause: org.postgresql.util.PSQLException: This connection has been closed.: org.apache.ibatis.exceptions.PersistenceException: 

Error querying database. Cause: org.postgresql.util.PSQLException: This connection has been closed. 

The error may exist in org/activiti/db/mapping/entity/Job.xml 
The error may involve org.activiti.engine.impl.persistence.entity.JobEntity.selectNextJobsToExecute 

在执行查询

SQL: select  RES.*   from ACT_RU_JOB RES   LEFT OUTER JOIN ACT_RU_EXECUTION PI ON PI.ID_ = RES.PROCESS_INSTANCE_ID_  where (RES.RETR 
IES_ > 0)  and (RES.DUEDATE_ is null or RES.DUEDATE_ < ?)  and (RES.LOCK_OWNER_ is null or RES.LOCK_EXP_TIME_ < ?) and (  (RES.EXECUTION_ID_ 
is null)  or  (PI.SUSPENSION_STATE_ = 1)  )  LIMIT ? OFFSET ? 

Cause: org.postgresql.util.PSQLException: This connection has been closed. 
at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:23) [mybatis-3.1.1.jar:3.1.1] 
at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:104) [mybatis-3.1.1.jar:3.1.1] 
at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:95) [mybatis-3.1.1.jar:3.1.1] 
at org.activiti.engine.impl.db.DbSqlSession.selectListWithRawParameter(DbSqlSession.java:301) [activiti-engine-5.11.jar:5.11] 
at org.activiti.engine.impl.db.DbSqlSession.selectList(DbSqlSession.java:292) [activiti-engine-5.11.jar:5.11] 
at org.activiti.engine.impl.db.DbSqlSession.selectList(DbSqlSession.java:287) [activiti-engine-5.11.jar:5.11] 
at org.activiti.engine.impl.db.DbSqlSession.selectList(DbSqlSession.java:274) [activiti-engine-5.11.jar:5.11] 
at org.activiti.engine.impl.persistence.entity.JobManager.findNextJobsToExecute(JobManager.java:105) [activiti-engine-5.11.jar:5.11] 
at org.activiti.engine.impl.cmd.AcquireJobsCmd.execute(AcquireJobsCmd.java:50) [activiti-engine-5.11.jar:5.11] 
at org.activiti.engine.impl.cmd.AcquireJobsCmd.execute(AcquireJobsCmd.java:33) [activiti-engine-5.11.jar:5.11] 
at org.activiti.engine.impl.interceptor.CommandExecutorImpl.execute(CommandExecutorImpl.java:24) [activiti-engine-5.11.jar:5.11] 
at org.activiti.engine.impl.interceptor.CommandContextInterceptor.execute(CommandContextInterceptor.java:60) [activiti-engine-5.11.jar:5.11] 
at org.activiti.engine.impl.interceptor.LogInterceptor.execute(LogInterceptor.java:32) [activiti-engine-5.11.jar:5.11] 
at org.activiti.engine.impl.jobexecutor.AcquireJobsRunnable.run(AcquireJobsRunnable.java:61) [activiti-engine-5.11.jar:5.11] 
at java.lang.Thread.run(Thread.java:662) [rt.jar:1.6.0_32] 
Caused by: org.postgresql.util.PSQLException: This connection has been closed. 
at org.postgresql.jdbc2.AbstractJdbc2Connection.checkClosed(AbstractJdbc2Connection.java:714) 
at org.postgresql.jdbc3.AbstractJdbc3Connection.prepareStatement(AbstractJdbc3Connection.java:274) 
at org.jboss.jca.adapters.jdbc.BaseWrapperManagedConnection.doPrepareStatement(BaseWrapperManagedConnection.java:677) 
at org.jboss.jca.adapters.jdbc.BaseWrapperManagedConnection.prepareStatement(BaseWrapperManagedConnection.java:663) 
at org.jboss.jca.adapters.jdbc.WrappedConnection.prepareStatement(WrappedConnection.java:404) 
at org.apache.ibatis.executor.statement.PreparedStatementHandler.instantiateStatement(PreparedStatementHandler.java:72) [mybatis-3.1.1.jar:3.1.1] 
at org.apache.ibatis.executor.statement.BaseStatementHandler.prepare(BaseStatementHandler.java:82) [mybatis-3.1.1.jar:3.1.1] 
at org.apache.ibatis.executor.statement.RoutingStatementHandler.prepare(RoutingStatementHandler.java:54) [mybatis-3.1.1.jar:3.1.1] 
at org.apache.ibatis.executor.SimpleExecutor.prepareStatement(SimpleExecutor.java:70) [mybatis-3.1.1.jar:3.1.1] 
at org.apache.ibatis.executor.SimpleExecutor.doQuery(SimpleExecutor.java:56) [mybatis-3.1.1.jar:3.1.1] 
at org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:267) [mybatis-3.1.1.jar:3.1.1] 
at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:141) [mybatis-3.1.1.jar:3.1.1] 
at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:105) [mybatis-3.1.1.jar:3.1.1] 
at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:81) [mybatis-3.1.1.jar:3.1.1] 
at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:101) [mybatis-3.1.1.jar:3.1.1] 
... 13 more 
+0

码码码码码plzzzzzzz – madhairsilence

+0

对不起madhairsilence这是不可能的共享代码,你能告诉场景中,这个异常发生。 – sai576

+0

你解决了这个问题吗?是你的JDBC隔离级别Read committed/Transaction_read_committed? – Kevin

回答

2

我不得不使用PHP类似的问题发生错误。问题的原因是我嵌套连接。内部连接返回数据后,外部连接返回关闭。 解决方案很简单:连续处理两个连接,这意味着在这种情况下,我首先执行先前的内部连接,然后执行原始外部连接。

象征:

try{ 
    firstConnection = createConnection(); 
    results = firstConnection.query(...); 
    if results == true then 
    secondConnection = createConnection(); 
    resultsToo = secondConnection.query(); 
    if resultsToo == true then 
     processResults(resultsToo); 
     closeConnection(); 
    end if; 
    processResults(results); 
    closeConnection(); 
    end if; 
exceptionHandling(); 

处理第二连接第一连接解决我的问题了。

0

问题可通过去除默认Activiti的数据源配置这个选项来解决

<property name="defaultAutoCommit" value="false" />