0

Using cron4j, one can set up a job to run in some time in a future

    Scheduler s = new Scheduler();
    s.schedule("5 10 * * *", job);
    s.start();

Using cron4j, can the job be scheduled to start "next Saturday", or on "12/21/2012"?

James Raitsev
  • 92,517
  • 154
  • 335
  • 470

3 Answers3

2
*     *     *   *    *        command to be executed
-     -     -   -    -
|     |     |   |    |
|     |     |   |    +----- day of week (0 - 6) (Sunday=0)
|     |     |   +------- month (1 - 12)
|     |     +--------- day of        month (1 - 31)
|     +----------- hour (0 - 23)
+------------- min (0 - 59)

This is the basic break down of the command structure. starting something one the 21 would look like

0 0 21 12 *

But this would only run on the 21 of the 12 month every year.

nate_weldon
  • 2,289
  • 1
  • 26
  • 32
1

I'm not sure you can define the year but since the fields are minute hour day month day_of_week (year) you should be able to at least let the job run at 12/21/2012 using this expression: 0 0 21 12 ? 2012.

Edit: cron4j doesn't seem to support the optional year expression, so it seems you can just define 0 0 21 12 * and have the job run every December 21st.

Thomas
  • 87,414
  • 12
  • 119
  • 157
1

Yes. For example:

0 0 21 12 *

This says run this at 12:00 AM on December 21st.

The Chron syntax does not finitely support a year setting, but if you set this job today, it would run the next time it crosses that date.

Note: The other answer suggests adding a year column. If you do include this, the behavior is not entirely predictable -- it depends which chron implementation you're using.

ametren
  • 2,186
  • 15
  • 19