简体   繁体   English

如何放弃僵尸工作?

[英]How to abandon zombie jobs?

I am using Spring Batch in a web application. 我在Web应用程序中使用Spring Batch。 The jobs are run by a custom TaskExecutor that manages the submitted Runnable s in a queue and executes them one after another. 作业由自定义TaskExecutor运行,该TaskExecutor管理队列中已提交的Runnable ,并一个接一个地执行它们。 Thus many jobs have the status STARTING or STARTED for a long time. 因此,许多作业的状态长时间为STARTINGSTARTED

Now it happend that the server was shutdown while there were still jobs in the queue. 现在碰巧在队列中仍有作业时服务器已关闭。 After a restart of the server the jobs are still marked as running, but instead they should be abandoned. 重新启动服务器后,作业仍被标记为正在运行,但应将其放弃。

How can this be done? 如何才能做到这一点?

Spring Batch provides no tools out of the box for something like this. Spring Batch没有提供开箱即用的工具。 The reason for that is that this typically requires a human decision of some kind on what conditions this type of behavior is appropriate. 这样做的原因是,这通常需要人为决定哪种类型的行为适合哪种条件。

That being said, in your case, if you are not running in a clustered environment, you could create a component that, on the initialization of the application context, examines the job repository and updates the statuses as required (similar to how you can initialize a datasource on startup). 话虽如此,如果您不是在集群环境中运行,则可以创建一个组件,该组件在应用程序上下文初始化时检查作业存储库并根据需要更新状态(类似于如何初始化)启动时的数据源)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM