长期运行的Spring Batch Jobs中的TransactionSystemException

时间:2015-04-30 00:00:34

标签: spring-batch jobs rollback

我有一个Spring Batch Job,有时运行时间超过2700秒。当他们这样做时,我注意到来自spring批处理框架的异常。

SpringFramework版本:

<spring-batch.version>2.2.7.RELEASE</spring-batch.version>
<spring.framework.version>4.0.3.RELEASE</spring.framework.version>

这是工作的定义:

<batch:job id="MyJob">
    <batch:step id="trigger-job" next="poll-job">
        <batch:tasklet ref="triggerJobStep" />
        <batch:listeners>
            <batch:listener ref="phaseStepListener" />
        </batch:listeners>
    </batch:step>
    <batch:step id="poll-job">
        <batch:tasklet ref="pollJobStatusStep" />
        <batch:listeners>
            <batch:listener ref="phaseStepListener" />
        </batch:listeners>
    </batch:step>

    <batch:listeners>
        <batch:listener ref="phaseCompletionListener" />
    </batch:listeners>
</batch:job>

似乎与数据库的连接已经用完。

在轮询正在花费很长时间的服务时,这个问题总会发生。

如果有任何建议或其他方法,请告诉我们!

另请注意,对于运行时间不长的作业而言,&lt; 2700秒,没有问题。

如果您需要更多信息,请与我们联系。

谢谢, 戴夫

工作的堆栈痕迹:

"errorMessage":"Step requested termination: StepExecution: id=15365, version=2, name=poll-cmpaas-deploy, status=UNKNOWN, exitStatus=FAILED, readCount=0, filterCount=0, writeCount=0 readSkipCount=0, writeSkipCount=0, processSkipCount=0, commitCount=0, rollbackCount=1, 
exitDescription=org.springframework.transaction.TransactionSystemException: Could not roll back JPA transaction; nested exception is javax.persistence.PersistenceException: unexpected error when rollbacking
    at org.springframework.orm.jpa.JpaTransactionManager.doRollback(JpaTransactionManager.java:546)
    at org.springframework.transaction.support.AbstractPlatformTransactionManager.processRollback(AbstractPlatformTransactionManager.java:849)
    at org.springframework.transaction.support.AbstractPlatformTransactionManager.rollback(AbstractPlatformTransactionManager.java:826)
    at org.springframework.transaction.support.TransactionTemplate.rollbackOnException(TransactionTemplate.java:164)
    at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:137)
    at org.springframework.batch.core.step.tasklet.TaskletStep$2.doInChunkContext(TaskletStep.java:267)
    at org.springframework.batch.core.scope.context.StepContextRepeatCallback.doInIteration(StepContextRepeatCallback.java:77)
    at org.springframework.batch.repeat.support.RepeatTemplate.getNextResult(RepeatTemplate.java:368)
    at org.springframework.batch.repeat.support.RepeatTemplate.executeInternal(RepeatTemplate.java:215)
    at org.springframework.batch.repeat.support.RepeatTemplate.iterate(RepeatTemplate.java:144)
    at org.springframework.batch.core.step.tasklet.TaskletStep.doExecute(TaskletStep.java:253)
    at org.springframework.batch.core.step.AbstractStep.execute(AbstractStep.java:195)
    at org.springframework.batch.core.job.SimpleStepHandler.handleStep(SimpleStepHandler.java:141)
    at org.springframework.batch.core.job.flow.JobFlowExecutor.executeStep(JobFlowExecutor.java:64)
    at org.springframework.batch.core.job.flow.support.state.StepState.handle(StepState.java:60)
    at org.springframework.batch.core.job.flow.support.SimpleFlow.resume(SimpleFlow.java:151)
    at org.springframework.batch.core.job.flow.support.SimpleFlow.start(SimpleFlow.java:130)
    at org.springframework.batch.core.job.flow.FlowJob.doExecute(FlowJob.java:135)
    at org.springframework.batch.core.job.AbstractJob.execute(AbstractJob.java:301)
    at org.springframework.batch.core.launch.support.SimpleJobLauncher$1.run(SimpleJobLauncher.java:134)
    at java.lang.Thread.run(Unknown Source)
Caused by: javax.persistence.PersistenceException: unexpected error when rollbacking
    at org.hibernate.jpa.internal.TransactionImpl.rollback(TransactionImpl.java:111)
    at org.springframework.orm.jpa.JpaTransactionManager.doRollback(JpaTransactionManager.java:542)
    ... 20 more
Caused by: org.hibernate.TransactionException: rollback failed
    at org.hibernate.engine.transaction.spi.AbstractTransactionImpl.rollback(AbstractTransactionImpl.java:217)
    at org.hibernate.jpa.internal.TransactionImpl.rollback(TransactionImpl.java:108)
    ... 21 more
Caused by: org.hibernate.TransactionException: unable to rollback against JDBC connection
    at org.hibernate.engine.transaction.internal.jdbc.JdbcTransaction.doRollback(JdbcTransaction.java:167)
    at org.hibernate.engine.transaction.spi.AbstractTransactionImpl.rollback(AbstractTransactionImpl.java:211)
    ... 22 more
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Communications link failure during rollback(). Transaction resolution unknown.
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
    at com.mysql.jdbc.Util.getInstance(Util.java:386)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1015)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:989)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:975)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:920)
    at com.mysql.jdbc.ConnectionImpl.rollback(ConnectionImpl.java:5101)
    at com.mchange.v2.c3p0.impl.NewProxyConnection.rollback(NewProxyConnection.java:860)
    at org.hibernate.engine.transaction.internal.jdbc.JdbcTransaction.doRollback(JdbcTransaction.java:163)
    ... 23 more
Could not roll back JPA transaction; nested exception is javax.persistence.PersistenceException: unexpected error when rollbacking","warningMessage":null,"data":null}'

1 个答案:

答案 0 :(得分:0)

45分钟后您的数据库连接被切断。您的服务器正在查杀它,或者(更有可能)您的应用程序和数据库之间有防火墙正在终止长时间打开的持久连接(防火墙通常会切断持久连接,无论它们在一段时间后是否正在使用时间)。假设它是防火墙,您需要将其配置为不切断连接。