-1
我有一個彈簧批量作業,有時運行時間超過2700秒。當他們這樣做時,我注意到來自Spring批處理框架的異常。長時間運行彈簧批量作業中的TransactionSystemException
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>
好像連接到數據庫已經不多了。
這個問題總是發生在我輪詢一個需要很長時間的服務時。
如果有任何建議或其他方法,請讓我知道!
另外請注意,對於那些運行時間不長的工作,這是沒有問題的。
如果您需要更多信息,請讓我知道。
謝謝, 戴夫
工作的堆棧跟蹤:45分鐘後
"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}'
謝謝邁克爾,我覺得有一個數據庫連接丟失的問題。這是我的問題。在我的工作中,我沒有使用數據庫。看來SpringBatch存在這個問題。那麼其他人如何處理可能運行10-14小時的工作呢?我可以使用另一種策略嗎?在我的工作中,我有一個監控另一個過程的步驟。這一步有一個睡眠while循環。當其他過程完成時,作業將退出。感謝您的任何意見或建議。 –
我發現了這個問題。在我的腳步裏,我有一個等待工作完成的循環。如果時間超過40+分鐘以上的某段時間,SpringBatch顯然不會這樣。解決方案是返回RepeatStatus.CONTINUABLE並再次調用。 –