Exploring cron Expression

cron is a UNIX tool that has been around for a long time, so its scheduling capabilities are powerful and proven. The CronTrigger class is based on the scheduling capabilities of cron.

CronTrigger uses “cron expressions” for scheduling .

* * * * * command to execute
– – – – –
¦ ¦ ¦ ¦ ¦
¦ ¦ ¦ ¦ ¦
¦ ¦ ¦ ¦ +—– day of week (0 – 7) (0 to 6 are Sunday to Saturday, or use names; 7 is Sunday, the same as 0)
¦ ¦ ¦ +———- month (1 – 12)
¦ ¦ +————— day of month (1 – 31)
¦ +——————– hour (0 – 23)
+————————- min (0 – 59)

Some Example according to cron Expresssions :-

Some cron examples ,

Expression Execution Detail Comment
  5  2  *  *  6  This CRON job starting at Current-DateTime (now), it would run:

  1. 2014-11-29 02:05:00
  2. 2014-12-06 02:05:00
  3. 2014-12-13 02:05:00
  4. 2014-12-20 02:05:00
  5. 2014-12-27 02:05:00
 

 

Once in a week

  5  2  *  *  *  This CRON job starting at Current-DateTime (now), it would run:

  1. 2014-11-26 02:05:00
  2. 2014-11-27 02:05:00
  3. 2014-11-28 02:05:00
  4. 2014-11-29 02:05:00
  5. 2014-11-30 02:05:00

 

 

 

Once in a Day

5  */12  *  *  *  This CRON job starting at Current-DateTime (now), it would run:

  1. 2014-11-25 12:05:00
  2. 2014-11-26 00:05:00
  3. 2014-11-26 12:05:00
  4. 2014-11-27 00:05:00
  5. 2014-11-27 12:05:00

 

 

 

Twice in a Day

5  */6  *  *  * This CRON job starting at Current-DateTime (now), it would run:

  1. 2014-11-25 12:05:00
  2. 2014-11-25 18:05:00
  3. 2014-11-26 00:05:00
  4. 2014-11-26 06:05:00
  5. 2014-11-26 12:05:00
  6. 2014-11-26 18:05:00
  7. 2014-11-27 00:05:00

 

 

 

4-times a Day