Show TOC Start of Content Area

Background documentation Scheduling Jobs with Cron Start Conditions  Locate the document in its SAP Library structure

This section outlines the attributes of the CronEntry class.

Cron Entries

In the NetWeaver Scheduler for Java, CronEntry instances provide functionality similar to that of the crontab command in Unix. 

The CronEntry class specifies several attributes outlined in the table below.

CronEntry Attributes

Attribute

CronField Class Counterpart

Meaning

Year

CronYearField

The year in which you want the job to run

Month

CronMonthField

The month in which you want the job to run

Day of Month

CronDOMField

The day of month in which you want the job to run

Day of Week

CronDOWField

The day of week in which you want the job to run

Hour

CronHourField

The hour in which you want the job to run

Minute

CronMinuteField

The minute in which you want the job to run

You use the CronEntry attributes to specify the date and time and how often you want a an instance of a job definition to run relative to the start/ and of the month and year.

Regarding the representation of the attributes that you instantiate in a CronEntry, the Scheduler API offers two sets of CronEntry constructors:

With the two constructors from the snippets below, you pass the fileds of the CronEntry class as string.

//Takes the time zone from the local machine

CronEntry(String cron_entry)

 

//Takes a specified time zone

CronEntry(String cron_entry, TimeZone tz)

 

With the two constructors from the snippets below, you pass the class attributes as instances of the CronField classes.

//Takes the time zone from the local machine

CronEntry(CronYearField years, CronMonthField months, CronDOMField dom, CronDOWField dow, CronHourField hours, CronMinuteField minutes)

 

//Takes a specified time zone

CronEntry(CronYearField years, CronMonthField months, CronDOMField dom, CronDOWField dow, CronHourField hours, CronMinuteField minutes, TimeZone tz)

Each CronField instance can be constructed as a string.

Rules for the CronEntry Fields String Representation

Fields Order

In the string representation that you pass to a CronEntry, every filed has a fixed position: the string for Yearcomes first, followed by that for Month, Day of month, Day of week, Hour, and Minute, as the figure below shows.

This graphic is explained in the accompanying text

CronEntry Field Position

The fields are separated by colon (:).

Note

Make sure you do not leave spaces before or after the field values.

Filed Ranges

Every field has a possible range of the values it can take, as specified in the table below:

CronEntry Field Value Range

Field

Possible Value

Year

2006 – infinity

Month

0 – 11.

0 stands for January.

Day of month

1 – 31

Day of week

1 – 7.

1 stands for Sunday, 2 – for Monday, and so on.

Hour

0 – 23

Minute

0 – 59

For example, the CronEntry from the snippet below will run on the 3rd of January and every Sunday in January at 1:15 AM in 2007. The entry will run in the current time zone of the local machine (GMT).

The exact execution times are shown in below the CronEntry.

CronEntry myEntry = new CronEntry ("2007:0:3:1:1:15")

Execution times:

Wed Jan 03 01:15:00 EET 2007

Sun Jan 07 01:15:00 EET 2007

Sun Jan 14 01:15:00 EET 2007

Sun Jan 21 01:15:00 EET 2007

Sun Jan 28 01:15:00 EET 2007

 

Operators

There are several ways to specify multiple values for fields as listed below:

     Asterisk (*)

This value means “from first to last”, “every”. Every field can take this value. For example, the string (*:*:*:*:*:*) means every minute of every hour every day into infinity.

     Comma (,)

By using a comma, you specify a list of values for a field. For example, the value 7,1 for the Day of week field means every weekend.

     Dash (-)

By using a dash, you specify a range of values for a field. For example, the value 3-7 for the Day of month field means from the 3rd to the 7th of the month, that is on days 3, 4, 5, 6, and 7 of the month.

You can combine the use of comma and dash to specify list of ranges for a field. For example, the value 0-2, 6-8 for the Month field means January, February, March and July, August, September.

     Slash (/)

By using a slash you can specify a step for a field: x/y means every y of x. You can use slash together with asterisk(*) and dash(-).

For, example the value 0-23/2 for the Hour field means every other hour starting from 0, that is 12 AM, 2 AM, 4 AM, 6 AM and so on.  Defining hours as 0-23/2 is the same as */2.

The value */15 for the Minute field means every quarter of an hour, starting from 0, that is 0, 15, 30, 45 within one hour.

 

The day of execution of a CronEntry can be specified by two fields: Day of month and Day of week. The relation between the two is a logical OR.

If in the same CronEntry, you specify values for both fields (that is, none of the fields is *), then the job runs when either of the two conditions is fulfilled. For example, the value 2:2 for Day of month and Day of week means that the cron job will run every second day of the month and every Monday.

If only one of the fields is specified, and the other is *, then the cron job runs on the specified day. For example, the value *:2 means every Monday of every month.

If both Day of month and Day of week are *, then the job runs every day.

See also:

 

Scheduling Jobs with Recurrent Start Conditions

 

End of Content Area