Is it possible to kill a current running Quartz Job?

前端 未结 3 780
梦谈多话
梦谈多话 2021-01-04 05:48

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

3条回答
  •  一生所求
    2021-01-04 06:13

    I don't know why nobody mentioned this, or maybe this was not available at the time the question was asked.

    There is a method called shutdown for a Scheduler instance.

     SchedulerFactory factory = new StdSchedulerFactor();
     Scheduler scheduler = factory.getScheduler();
    

    The above is used to start a job like

      scheduler.start();
    

    Use a flag or something to know when to stop the job from running. Then use

     scheduler.shutdown();
    

    How I implemented my requirement:

     if(flag==true)
    {
        scheduler.start();
        scheduler.scheduleJob(jobDetail, simpleTrigger);
    }
    else if(flag==false)
    {
        scheduler.shutdown();
    }
    

    Where jobDetail and simpleTrigger are self explanatory.

    Hope it helps. :)

提交回复
热议问题