Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Quartz's CronTrigger for every two hours

I want to schedule a component with Quartz's CronTrigger for every two hours. What is the correct cron expression to achieve this?

like image 389
vk007 Avatar asked Oct 07 '11 05:10

vk007


People also ask

What is the cron expression for every 5 minutes?

“At every 5th minute.” Cron job every 5 minutes is a commonly used cron schedule. We created Cronitor because cron itself can't alert you if your jobs fail or never start.

What is CronTrigger?

CornTrigger is an object in salesforce which contains schedule information for a scheduled job . Basically it hold the CronExpression,NextFireTime,LastFireTime,StartTime ,End Time ,status etc .

How do you make a CronTrigger?

Create a CronTrigger with the given name and group, associated with the identified JobDetail , and with the given "cron" expression. Create a CronTrigger with the given name and group, associated with the identified JobDetail , and with the given "cron" expression resolved with respect to the TimeZone .

What is Quartz cron expression?

A Cron Expressions quartz. Trigger. A cron expression is a string consisting of six or seven subexpressions (fields) that describe individual details of the schedule. These fields, separated by white space, can contain any of the allowed values with various combinations of the allowed characters for that field.

What is crontrigger in quartz scheduler?

Trigger is the base interface for all triggers. One such implementation is CronTrigger which uses cron- expression with the help of CronScheduleBuilder. Here in this page we will describe each and every term for Quartz scheduler getting started.

How to instantiate a trigger in quartz?

To instantiate Trigger, we need to use TriggerBuilder . Many triggers can point to same job, but a single trigger can point only one job. It means we can explain in way that the relationship between trigger and job is many-to-one but not one-to-many. org.quartz.CronTrigger helps to start a job using Unix cron- like schedule definitions.

How to schedule a job in quartz?

Quartz provides easy steps to schedule our job. It provides a Job interface using which we have to create our job that will be scheduled. Now instantiate Scheduler using SchedulerFactory. Create a JobDetail and Trigger that will be registered to Scheduler and finally start it. Trigger is the base interface for all triggers.

How do I create a crontrigger with a schedule?

CronTrigger instances are built using TriggerBuilder (for the trigger's main properties) and WithCronSchedule extension method (for the CronTrigger-specific properties). You can also use CronScheduleBuilder's static methods to create schedules. Build a trigger that will fire every other minute, between 8am and 5pm, every day:


2 Answers

You probably want a cron expression like:

"0 0 0/2 * * ?" 
like image 125
Codo Avatar answered Sep 24 '22 19:09

Codo


Using quartz scheduler. Following cron expression for executing job two hour.

String cronExpression = "0 0/120 * * * ?"; 
like image 20
Neeraj Gahlawat Avatar answered Sep 21 '22 19:09

Neeraj Gahlawat