由于RollbackException,Spring Batch无法更新其状态

时间:2011-12-15 13:09:53

标签: java spring spring-batch

似乎Spring Batch在与它调用的ejbs相同的事务中运行。因此,当我们在ejbs中获得回滚时,Spring Batch无法在数据库中更新其状态。

我们得到的例外是:

    org.springframework.batch.core.step.FatalStepExecutionException: JobRepository failure forcing exit with unknown status
    at org.springframework.batch.core.step.tasklet.TaskletStep$ChunkTransactionCallback.doInTransaction(TaskletStep.java:418)
    at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:130)
    at org.springframework.batch.core.step.tasklet.TaskletStep$2.doInChunkContext(TaskletStep.java:262)
    at org.springframework.batch.core.scope.context.StepContextRepeatCallback.doInIteration(StepContextRepeatCallback.java:76)
    at org.springframework.batch.repeat.support.RepeatTemplate.getNextResult(RepeatTemplate.java:367)
    at org.springframework.batch.repeat.support.RepeatTemplate.executeInternal(RepeatTemplate.java:214)
    at org.springframework.batch.repeat.support.RepeatTemplate.iterate(RepeatTemplate.java:143)
    at org.springframework.batch.core.step.tasklet.TaskletStep.doExecute(TaskletStep.java:248)
    at org.springframework.batch.core.step.AbstractStep.execute(AbstractStep.java:195)
    at org.springframework.batch.core.job.SimpleStepHandler.handleStep(SimpleStepHandler.java:135)
    at org.springframework.batch.core.job.flow.JobFlowExecutor.executeStep(JobFlowExecutor.java:61)
    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:144)
    at org.springframework.batch.core.job.flow.support.SimpleFlow.start(SimpleFlow.java:124)
    at org.springframework.batch.core.job.flow.FlowJob.doExecute(FlowJob.java:135)
    at org.springframework.batch.core.job.AbstractJob.execute(AbstractJob.java:281)
    at org.springframework.batch.core.launch.support.SimpleJobLauncher$1.run(SimpleJobLauncher.java:120)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
    at java.lang.Thread.run(Thread.java:662)
Caused by: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is java.sql.SQLException: Error in allocating a connection. Cause: javax.transaction.RollbackException

如果步骤失败,我们如何确保Spring Batch能够更新其状态?这是Spring Batch中的错误,还是我们做错了什么?

2 个答案:

答案 0 :(得分:-1)

批次是否也在ejb内运行? ejbs的交易设置是什么? BMT还是CMT?你在批处理中从哪里调用EJB?读者,处理器,作家?监听?您是否尝试通过代码中的常规catch(Exception e)处理导致ejb回滚的异常,跳过或重试?

答案 1 :(得分:-2)

似乎问题出现在我们的joblaunchers配置中。

我们有一些进程启动其他进程,当他们使用相同的taskExecutor实例时,回滚会回滚任务本身。

不是100%确定这是否修正了错误,但它现在正在运作: - )