1

I am using Postgres database.Sometimes the connection closed automatically while interacting with my application.Sometimes even i am not interacting with my application sitting ideal at that time also connection closed.It shows follwing excepion.My server log is

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

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.
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
3
  • code code code code code plzzzzzzz Commented May 15, 2013 at 5:42
  • Sorry madhairsilence it's not possible to share the code,Could you please tell the scenarios in which this exception occurs. Commented May 15, 2013 at 8:58
  • Did you fix this problem? was your JDBC isolation level Read committed / Transaction_read_committed? Commented Aug 28, 2013 at 15:17

2 Answers 2

2

I have had a similar problem using PHP. The cause of the problem was that I was nesting connections. The outer connection returned being closed after the inner connection had returned its data. The solution was simple: to process both connection serially, which meant in this case that I first executed the previously inner connection and afterwards the original outer connection.

Symbolically:

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();

Processing the second connection before the first connection solved my issue.

Sign up to request clarification or add additional context in comments.

2 Comments

woo hoo... who would use connection with in a connection? that's a bad idea!
@SyedSirajUddin: The information from the first query was required to know if a second query was useful to make and which query exactly had to be made. The code above was simplified. In between there was a processing of the first query. The database language is not very good at processing the information of the query. Java is much better suited for that part of the process. Each program must do what he does best.
0

Issue can be solved by removing this option in default Activiti datasource configuration

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.