gpt4 book ai didi

java - Spring Batch 中是否可以抛出致命的不可回滚异常?

转载 作者:行者123 更新时间:2023-12-02 08:49:44 25 4
gpt4 key购买 nike

我尝试了 noSkip()、noRetry()、noRollback() 的所有组合,但没有实现。如果我在没有 noRollback(MyException.class) 的情况下设置步骤,则一旦处理的行引发异常,该步骤就会失败,但它会回滚所有数据库操作。如果我使用 noRollback(MyException.class),则数据库状态将保留,但我不会收到 fatal error 的日志,并且步骤不会中断/失败。

有什么方法可以直观地处理这个问题吗?这是我尝试的最后一个代码

  return this.stepBuilderFactory.get(STEP_PROCESS_ROWS)
.faultTolerant()
.noSkip(UnexpectedJobExecutionException.class)
.noRetry(UnexpectedJobExecutionException.class)
.noRollback(UnexpectedJobExecutionException.class)
.reader(myReader)
.processor(myProcessor)
.writer(myWriter)
.build();

最佳答案

Is it possible to throw a fatal non-rollbackable exception in Spring Batch?

是的,使用 FaultTolerantStepBuilder#noRollback正如你所做的那样。 noSkipnoRetry 具有不同的含义。

If I set the step without noRollback(MyException.class), the step fails as soon as the processed row throws the exception, but it rollbacks all db actions.

这是默认行为。如果发生异常,事务将回滚并且该步骤失败。

If I use noRollback(MyException.class), then the db state is persisted, but I get no log of the fatal error and step is not interrupted/failed.

这里没什么奇怪的(我希望):由于事务没有回滚,状态被持久化并且该步骤继续。确保将日志级别设置为调试以获取所有详细信息。

关于java - Spring Batch 中是否可以抛出致命的不可回滚异常?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60859552/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com