java 如何从石英表中删除未使用的触发器

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14748551/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 17:16:21  来源:igfitidea点击:

how to remove unused triggers from quartz tables

javaspringquartz-scheduler

提问by satya

I'm using spring with Quartz and every thing is working fine but some previously cofigured triggers also got executed because they are stored in Quartz tables. Manually we can delete all unconfigured triggers and execute the application but that is not a good practice. I want to remove all the triggers through a spring+quartz property or some other solution.

我在 Quartz 中使用 spring,一切正常,但一些以前配置的触发器也被执行,因为它们存储在 Quartz 表中。我们可以手动删除所有未配置的触发器并执行应用程序,但这不是一个好习惯。我想通过 spring+quartz 属性或其他一些解决方案删除所有触发器。

When I have configured 3 triggers in spring configuration file like

当我在 spring 配置文件中配置了 3 个触发器时

<property name="triggers">
    <list>
        <ref bean="FirstTrigger" />
        <ref bean="secondTrigger" />
        <ref bean="ThirdTrigger"/>
    </list>
</property>

When server started, all the triggers stored in Quartz tables with corresponding cron triggers and job details. If i remove any of the triggers in my configuration, in above for example I removed second Trigger, but it wasn't removed from Quartz tables. At that time DBtrigger (removed trigger) also executed.

服务器启动时,所有触发器都存储在 Quartz 表中,并带有相应的 cron 触发器和作业详细信息。如果我删除配置中的任何触发器,例如在上面的示例中,我删除了第二个触发器,但它没有从 Quartz 表中删除。那时DBtrigger(去除触发器)也执行了。

In spring + Quartz integration, is there any property to handle this problem or do we need to do something else for this problem?

在spring + Quartz集成中,是否有任何属性可以处理这个问题,或者我们需要为这个问题做些什么?

Thanks in advance.

提前致谢。

回答by snowindy

If you store triggers in DB (suppose your triggers are cron-based), you can simply delete records like this:

如果您将触发器存储在数据库中(假设您的触发器是基于 cron 的),您可以简单地删除这样的记录:

DELETE FROM QRTZ_CRON_TRIGGERS WHERE SCHED_NAME='scheduler' and TRIGGER_NAME='myTrigger' and TRIGGER_GROUP='DEFAULT';
DELETE FROM QRTZ_TRIGGERS WHERE SCHED_NAME='scheduler' and TRIGGER_NAME='myTrigger' and TRIGGER_GROUP='DEFAULT';

You may also consider looking around other Quartz DB tables to find leftovers related to your job.

您还可以考虑查看其他 Quartz DB 表以查找与您的工作相关的剩余部分。

回答by gaborsch

You can access the Quartz Scheduler, Jobs, Triggers, etc. using the Quartz API.

您可以使用Quartz API访问 Quartz Scheduler、Jobs、Triggers 等。

Have a look at this Quartz CookBook, you will find out how to list all the triggers defined, etc. Maybe you should remove the unnecessary triggers using this API.

看看这个Quartz CookBook,你会发现如何列出所有定义的触发器等。也许你应该使用这个 API 删除不必要的触发器。