本文介绍了重新部署应用程序后,杀死Quartz的线程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,我使用石英来安排一些作业在Glassfish上的Java应用程序中运行。
有时当我重新部署我的应用程序时,我忘记关闭我的调度程序,并且在部署新版本的应用程序后不可能阻止它们。
因此,问题是如何在应用程序未部署后停止/终止石英的线程。



这里是我添加job的代码:

pre $ SchedulerFactory sf =新的StdSchedulerFactory();
Scheduler sched sched = sf.getScheduler();

// 1:EMS2ELC JOB /////////////
String EMS2ELCScheduleEx =0 30 0 * *?;
job = new JobDetail(EMS2ELCJob,WebServicesGroup,EMS2ELCJob.class);
trigger = new CronTrigger(EMSTrigger,WebServicesGroup,EMS2ELCJob,WebServicesGroup,EMS2ELCScheduleEx,TimeZone.getTimeZone(America / Los_Angeles));
sched.addJob(job,true);
ft = sched.scheduleJob(trigger);
log.info(SchedulerController:+ job.getFullName()+已计划运行在:+ ft +并根据表达式重复:+ trigger.getCronExpression());


解决方案

当你说重新部署时, ,即没有终止glassfish服务器?你可以实现ServletContextListener.contextDestroyed()方法,并从那个调用quartz API提供的关闭钩子。您需要在web.xml中注册监听器

In my app i'm using quartz to schedule some jobs to run in my Java application on Glassfish.Sometimes when i'm redeploying my application i'm forgetting to turn off my scheduler and it's impossible to stop them after new version of app has been deployed.So, the question is how does one can stop/kill quartz's threads after application has been un-deployed.

Here is my code to add job:

        SchedulerFactory sf = new StdSchedulerFactory();
        Scheduler sched sched = sf.getScheduler();

        // 1: EMS2ELC JOB /////////////
        String EMS2ELCScheduleEx = "0 30 0 * * ?";
        job = new JobDetail("EMS2ELCJob", "WebServicesGroup", EMS2ELCJob.class);
        trigger = new CronTrigger("EMSTrigger", "WebServicesGroup", "EMS2ELCJob", "WebServicesGroup", EMS2ELCScheduleEx, TimeZone.getTimeZone("America/Los_Angeles"));
        sched.addJob(job, true);
        ft = sched.scheduleJob(trigger);
        log.info("SchedulerController: " + job.getFullName() + " has been scheduled to run at: " + ft + " and repeat based on expression: " + trigger.getCronExpression());
解决方案

When you say re-deploying, is it hot deployment, i.e. without terminating glassfish server? You can implement ServletContextListener.contextDestroyed() method and from that call the shutdown hook provided by quartz API. You would need to register your listener in web.xml

这篇关于重新部署应用程序后,杀死Quartz的线程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 00:11