Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I set priorities to quartz trigger?

I am using Quartz Scheduler and there are 15 jobs. For each job there is one trigger. I want to set priority for each trigger. I can set low priority as 10 and high priority as 1. But as I am having 15 triggers for 15 jobs I need different priority for each trigger. e.g trigger1 will have priority 10, trigger2 will have priority 9. In this way I need to give same priority for two triggers.

So if two triggers with same priority will get execute at same time then which trigger will execute first?

Can anyone tell me how I can set different priorities for different triggers?

like image 347
Priya Avatar asked Aug 04 '11 12:08

Priya


People also ask

How do you trigger Quartz scheduler?

build(); // Tell quartz to schedule the job using our trigger sched. scheduleJob(job, trigger); The block of code that builds the job definition is using methods that were statically imported from the JobBuilder class.

How many jobs can Quartz handle?

The actual number of jobs that can be running at any moment in time is limited by the size of the thread pool. If there are five threads in the pool, no more than five jobs can run at a time.

What is Quartz misfire?

A misfire occurs if a persistent trigger “misses” its firing time because of the scheduler being shutdown, or because there are no available threads in Quartz's thread pool for executing the job. The different trigger types have different misfire instructions available to them.

How do I start a Quartz job?

Example 3 - Cron-based TriggersStart up the Quartz Scheduler. Schedule several jobs using various features of CronTrigger. Wait for 300 seconds (5 minutes) to give Quartz a chance to run the jobs. Shut down the Scheduler.


1 Answers

Trigger have a property called WithPriority which takes a integer value. When multiple triggers are fired at the same time the scheduler will fire the trigger with the highest priority first. And if the two triggers have same priority then either trigger will get fired.

  • .WithPriority(15) will run first
  • .WithPriority(1) will be the last trigger
like image 120
Yuvraj Avatar answered Oct 04 '22 19:10

Yuvraj