Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

difference between pauseJob and pauseTrigger in quartz scheduler?

What is the difference between pauseJob() and pauseTrigger() in quartz scheduler? How can select one among them for use? now i want to pause/interept a specific job how can i do

my scheduler code is given bellow

JobDetail job = new JobDetail();
            job.setName("pollerjob"+pollerId);
            job.setJobClass(Pollersheduller.class);
            job.getJobDataMap().put("socialMediaObj", socialMediaObj);
            job.getJobDataMap().put("queue", queue);


            //configure the scheduler time
            SimpleTrigger trigger = new SimpleTrigger();
            trigger.setName("pollerSocial"+pollerId);
            trigger.setStartTime(new Date(System.currentTimeMillis() + 1000));
            trigger.setRepeatCount(SimpleTrigger.REPEAT_INDEFINITELY);
            trigger.setRepeatInterval(Long.parseLong(intervel));


            //schedule it
            Scheduler scheduler = null;
            try {
                scheduler = new StdSchedulerFactory().getScheduler();
                scheduler.start();
                scheduler.scheduleJob(job, trigger);
            } catch (SchedulerException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
like image 215
MiDhuN Avatar asked Dec 26 '22 00:12

MiDhuN


1 Answers

As you have probably noticed, in Quartz a single job can be associated with multiple triggers. And if you look into Quartz sources, you will see that the pauseJob method simply retrieves all triggers associated with the specified job and pauses them, whereas the pauseTrigger method pauses only a particular trigger. So that is the main difference.

Please note that pausing a job in Quartz does not pause a currently running running job, it merely prevents the job from being run in the future!

If you want to interrupt a running job, then you can use the interruptJob method defined in the org.quartz.Interruptable interface the job must implement. If your job implements this interface, then it is entirely up to you to implement the interrupting logic. For example, you can set some sort of a flag when the interruptJob method is called and then you need to check the value of this flag in the job's execute method.

like image 167
Jan Moravec Avatar answered Jan 13 '23 13:01

Jan Moravec