how to terminate Job immediately?

给你一囗甜甜゛ 提交于 2019-12-24 19:33:18

问题


I have tried to stop my job when it is running. But the job do not stop immediately. It is still running and then throws the log:

2019-12-03 13:23:48 [main] INFO  o.s.b.c.r.s.SimpleJobRepository - Parent JobExecution is stopped, so passing message on to StepExecution
2019-12-03 13:23:48 [main] INFO  o.s.b.c.s.ThreadStepInterruptionPolicy - Step interrupted through StepExecution
2019-12-03 13:23:48 [main] INFO  o.s.batch.core.step.AbstractStep - Encountered interruption executing step remindStep in job remindEntrustPayment : Job interrupted status detected.


How could I terminate Job immediately?


回答1:


There is no way to force immediate shutdown, especially when the control is in user's code. The StepInterruptionPolicy (which defaults to ThreadStepInterruptionPolicy that you see in your logs) is checked at chunk boundaries, this is when the control goes back to the framework and stops the job (which is explained in the Stopping a job section).

You can ask to stop a job using JobOperator#stop or by setting StepExecution#setTerminateOnly in your code when appropriate (using a listener for example).



来源:https://stackoverflow.com/questions/59151450/how-to-terminate-job-immediately

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!