问题描述
在JVM崩溃后如何重新启动Jobs?
How to restart Jobs after a JVM crash?
当我的JVM崩溃或系统出现故障时,我正在运行许多在Spring Batch框架中实现的Jobs.失败后如何重新启动这些作业?
I was running a lot of Jobs implemented in Spring Batch framework, when my JVM crashed or the system failed. How can I restart these Jobs after failure?
推荐答案
基本上,您可以执行以下操作:
Basically, you can do as follows:
-
在您的应用程序上下文中配置
JobExplorer
工厂bean:
在应用上下文中配置JobOperator
bean
Configure a JobOperator
bean in your applictaion context
查询jobExplorer以获取不同的作业名称:jobExplorer.getJobNames()
Query the jobExplorer for distinct job names: jobExplorer.getJobNames()
对于步骤(3)中的每个作业,请查询jobExplorer中未完成的作业:jobExplorer.findRunningJobExecutions(String jobName)
For each job from step (3), query the jobExplorer for unfinished jobs:jobExplorer.findRunningJobExecutions(String jobName)
对于步骤(4)中的每个JobExecution
,调用:jobOperator.restart(jobExecution.getJobId())
For each JobExecution
from step (4) invoke:jobOperator.restart(jobExecution.getJobId())
在启动任何其他作业之前,请确保在启动顺序中调用此过程
Make sure to call this procedure during boot sequence, before any other job is launched
从技术上讲,可以通过覆盖JobExecutionDao
合并findRunningJobExecutions()
之类的步骤3 + 4,但是当前的API不支持它.
Technically it is possible to merge steps 3+4 for something like findRunningJobExecutions()
by overriding JobExecutionDao
, but the current API doesn't support it.
有关上述Spring bean配置的帮助,请参阅参考文档
For help in aforementioned Spring bean configuration, consult the reference documentation
这篇关于JVM崩溃后的Spring Batch的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!