【问题标题】:Spring Batch failing to update its state because of RollbackException由于 RollbackException,Spring Batch 无法更新其状态
【发布时间】:2011-12-15 13:09:53
【问题描述】:

似乎 Spring Batch 与它调用的 ejb 在同一个事务中运行。因此,当我们在 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 中的错误,还是我们做错了什么?

【问题讨论】:

    标签: java spring spring-batch


    【解决方案1】:

    似乎问题出在我们的工作启动器配置中。

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

    不是 100% 确定这是否是修复错误的原因,但它现在可以工作了 :-)

    【讨论】:

      【解决方案2】:

      批处理是否也在 ejb 中运行? ejbs 的事务设置是什么? BMT还是CMT?您从批处理中的哪个位置调用 EJB?读取器、处理器、写入器?听众?您是否尝试通过代码中的常规 catch(Exception e)、跳过或重试来处理导致 ejb 回滚的异常?

      【讨论】:

      • 看来我们毕竟有一些停止的进程。我们在 writer 中调用 ejbs。不,我们没有处理所有异常。我们让它们失败,然后我们有另一个进程在一段时间后重新启动它们。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-09-11
      • 2021-10-07
      • 2018-03-01
      • 2019-11-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多