是否可以终止当前正在运行的 Quartz 作业? [英] Is it possible to kill a current running Quartz Job?

查看:77
本文介绍了是否可以终止当前正在运行的 Quartz 作业?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我记得我们不能终止当前正在运行的 Quartz 作业,但我们可以在需要时中断并进行布尔检查,是否需要进一步进行后续操作.

I remember that we cannot kill the current running Quartz Job but we can interrupt and have a boolean check wherever is necessary whether we need to proceed further with the subsequent operations or not.

即使我们实现了InterruptableJob 并调用scheduler.interrupt 来中断Job,当前执行的Job 仍会在服务器中运行.

Even when we implement the InterruptableJob and call the scheduler.interrupt to interrupt the Job, the current executed job will be still running in the server.

例如:

  1. 作业通过 Hibernate 触发了一个命名的 SQL 查询,这需要很长时间
  2. 调用了第三方服务器,第三方服务器响应时间过长

http://neopatel.blogspot.in/2011/05/quartz-stop-job.htmlhttp://forums.terracotta.org/forums/posts/list/3191.页面

有人可以纠正我的理解并向我解释我们如何杀死或停止当前"执行的 Job 吗?

Could someone corrects my understanding and explain me how we can kill or stop the "currently" executing Job ?

推荐答案

如您所说,在quartz 中没有办法残酷地"中断工作,在JAVA 中也不行.

As you told, there is no way to interrupt "brutally" a job in quartz, neither in JAVA.

您可以将作业的逻辑封装在一个单独的线程中,并使用 ExecutorService 运行它.

You can encapsulate your job's logic in a separate Thread and run it with the ExecutorService.

看看这个例子:https://stackoverflow.com/a/2275596/1517816

假设您的 QuartzJob 是 Test 类,并在 Task 类中移动您的业务逻辑.

Assume your QuartzJob is the Test class and move your business logic in the Task class.

希望能帮到你

这篇关于是否可以终止当前正在运行的 Quartz 作业?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆