Show TOC Start of Content Area

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

This section outlines the attributes of the RecurringEntry class. It lists various use cases for the different start conditions you can set for a RecurringEntry. In each case, it specifies the suitable RecurringEntryconstructor provided by the Scheduler API.

Recurring Entries

The RecurringEntry class specifies several attributes described in the table below.

RecurringEntry Attributes

Attribute

Meaning

Start time

The time of the first execution of job.

An instance of SchedulerTime.

End time

The time of the last execution of a job.

An instance of SchedulerTime.

Iterations

The number of times you want the job to run.

Period

The time between two successive job iterations, or the time from the moment the scheduler task is scheduled to the first execution of a job.

The period is specified in milliseconds.

You can use combinations of the RecurringEntry attributes to set various recurrent start conditions to jobs, as outlined in the section below.

Recurrent Start Conditions – Use Cases

Run a Job Once in the Future

With this start condition, the job runs only once at a specified point in time, for example, at 9 AM on April 30, 2010.

Constructor

RecurringEntry(SchedulerTime)

You have to create Calendar instance for the time you want the job to run and then pass it to a SchedulerTimeobject.

//Create Calendar instance and set date to April, 30, 2010

java.util.Calendar calendar = java.util.Calendar.getInstance();   calendar.set(Calendar.YEAR, 2010);

calendar.set(Calendar.MONTH, 3);

calendar.set(Calendar.DAY_OF_MONTH, 3);

calendar.set(Calendar.HOUR_OF_DAY, 9);

calendar.set(Calendar.MINUTE, 0);

java.util.Date date = calendar.getDate();

 

//Create SchedulerTime with the time of the Calendar instance

SchedulerTime time = new SchedulerTime(date, TimeZone.getDefault()) 

 

//Pass the SchedulerTime to the RecurringEntry

RecurringEntry re = new RecurringEntry (time)

For an example on how to create a scheduler task with a RecurreingEntry with these start conditions, see Creating a Scheduler Task for the HelloJob

Run Now and Repeat over an Interval

With this start condition, a job runs now, and then runs recurrently over a regular period of time (period), for example, every 1 minute. The time of the first job execution is within the timeframe of the period from the moment you schedule the scheduler task.

Constructor

RecurringEntry(long period)

With this constructor, you do not need to specify a start time for the job.

For a job, that runs every minute, the RecurringEntry instance looks like the snippet below:

RecurringEntry re = new RecurringEntry((long)60000)

 

With a period set to 60000 ms, the Scheduler Service calculates the time of the first job execution to 60000 ms after the RecurringEntry is created. You can schedule the scheduler task only after you have created the RecurringEntry. This is why, from the point of view of invoking the schedule method, the time of the first job execution is within one minute from the moment you schedule the task, as the graphic below shows.

 

This graphic is explained in the accompanying text

First execution time

Run at a Future Point of Time and Repeat Infinitely over an Interval

With this start condition, a job runs once at a specified point in time and then repeats forever over a regular interval. For example, a job runs at 8 AM on April, 24, 2007 and then runs again every 24 hours.

Constructor

RecurringEntry(SchedulerTime startTime, long period)

 

You have to create a Calendar instance for the first execution time of the job (start time) and then pass it to a SchedulerTime object. In the RecurringEntry, you initialize the time and specify the interval in milliseconds.

//Create calendar instance with date set to 8AM, April 24, 2010

java.util.Calendar calendar = java.util.Calendar.getInstance();

   ....                      

java.util.Date date = calendar.getDate();

 

//Create SchedulerTime with the time of the Calendar instance

SchedulerTime time = new SchedulerTime(date, TimeZone.getDefault())

 

//Call the SchedulerTime from the RecurringEntry

//and specify the value of the period in milliseconds

RecurringEntry re = new RecurringEntry (time, (long) 24*3600*1000)

 

In the example above, if you schedule the scheduler task after the time you passed to the RecurringEntryobject (8 AM, on April 24, 2010), then the moment of the first job execution is within 24 hours from the moment the schedule method is invoked. If you call the schedule() method before 8 AM, on April 24, 2010, then the moment of the first job execution is 8 AM, on April 24, 2010.

Run over an Interval within a Timeframe

With this start condition, a job runs once at a specified point in time (start time), and then runs again over a regular interval until a specified period of time (end time). The moment of the first job execution is at the specified start time. The time of the last job execution occurs before or exactly at the specified end time.

For example, a job runs for the first time at 5 PM on April 25, 2008, and then runs every 1 hour until 3 AM on April 28, 2008.

Constructor

RecurringEntry(SchedulerTime startTime, SchedulerTime endTime, long period)

 

You need separate SchedulerTimeinstances for the start time and the end time.

//Create calendar instances for the start and end times

java.util.Calendar calendar = java.util.Calendar.getInstance();

   ....                      

java.util.Date dateStart = calendar.getDate();

 

java.util.Calendar calendar = java.util.Calendar.getInstance();

   ....                      

java.util.Date dateEnd = calendar.getDate();

 

//Create separate SchedulerTime objects with the dateStart and dateEnd calendar instances

SchedulerTime startTime = new SchedulerTime(dateStart, TimeZone.getDefault());

SchedulerTime endTime = new SchedulerTime(dateEnd, TimeZone.getDefault());

 

//Create RecurringEntry object and pass to it the startTime and endTime SchedulerTime objects,

//as well as the period of one hour in milliseconds

RecurringEntry re = new RecurringEntry(startTime, endTime, 3600*1000);

 

In this example, if you schedule the scheduler task after the start time, the moment of the first job execution is within 1 hour after the schedule method invocation. After this, a job definition instance runs every one hour until 3 AM on April 28, 2008 when is the last execution of an instance of this job definition.

Run Several Times within a Timeframe

With this start condition, a job runs once at a specified point in time (start time) and repeats a specified number of times (iterations) over a calculated regular period until a specified point in time (end time).

The Scheduler Service calculates the period by the following formula:

period = (end time – start time) / number of iterations – 1

The difference between the end time and the start time is calculated in milliseconds.

For example, instances of a job definition are scheduled to run 7 times between 3:00 AM and 4:00 AM on a specified date. The first instance will run at 3:00 AM, and the last instance will run at 4:00 AM. In between, jobs will run 5 more times every 10 minutes.

Constructor

RecurringEntry(SchedulerTime startTime, SchedulerTime endTime, int iterations)

 

If you schedule the scheduler task after the start time as the figure below shows, the execution of the first job is skipped. The job executions that should have occurred between the specified start time and the moment of the schedule method invocation, are also skipped as the following figure shows.

This graphic is explained in the accompanying text

First execution time

Run at a Future Point of Time and Repeat Several Times over an Interval

With this start condition, a job runs once at a specified point in time (start time) and then runs a specified number of times (iterations) over a regular specified period. The time of the last job execution is calculated by the following formula

End time = start time + period * (number of iterations - 1)

For example, a job is scheduled to run at 3:00 AM and then run 7 times more every 10 minutes. The time of the last job execution will be at 4:00 AM.

Constructor

RecurringEntry(SchedulerTime startTime, long period, int iterations)

 

If you schedule the scheduler task after the specified start time of the RecurringEntryinstance, the execution of the first job is skipped. The job executions that would have occurred between the specified start time and the moment of the schedule method invocation, are also skipped. The time of the last job execution remains unchanged.

See also:

 

Scheduling Jobs with Cron Start Conditions

End of Content Area