Excluding Scheduled Job Executions from a Scheduler Task

Use

This section outlines the attributes and the use of the Filter class and shows how you can create and apply filters to a scheduler task.

Filters

The Filter class has two attributes - start time and end time - which specify the boundaries of a time frame.

You use Filter objects in a scheduler task to instruct the SAP NetWeaver Scheduler for Java not to execute the jobs that fall into the specified time frame. For example, you can instruct the scheduler not to run a particular job on holidays.

A filter is bound to a scheduler task, not to a particular RecurringEntry or CronEntry in a scheduler task. Conversely, a filter applies to the whole task, not to the individual RecurringEntry and/ or CronEntry objects in it. In effect, in a scheduler task containing multiple RecurringEntry and/ or CronEntry objects, you cannot filter out the job executions of just one of those RecurringEntry and/ or CronEntry objects.

You can apply multiple filters to the same scheduler task. To apply the same filter to all scheduler tasks, and thus instruct the scheduler not to execute any tasks at all within the time frame, you have to add the same Filter object to each scheduler task individually.

Applying Filters

The static method createSchedulerTask(...) of the SchedulerTask interface allows you to apply filters when creating a SchedulerTask .

When you do not provide this method with filters, you cannot add filters to the obtained SchedulerTask object anymore. You can rather add filters to the task after scheduling the SchedulerTask object with the schedule(SchedulerTask task) method of the Scheduler interface. The Scheduler interface provides the methods:

  • addFilters(SchedulerTaskID id, Filter[] f) - adds a filter to the filters already added to the task

  • setFilters(SchedulerTaskID id, Filter[] f) - removes the current filters from the task and applies the filters you pass as arguments of the method

The following snippet shows how you can create and add filters to a scheduler task.

In the example we use a scheduler task that contains a RecurringEntry that schedules a job every hour from the current time on. Observe that the first execution time is ignored, because it is not in the future when the task is scheduled.

For information how to get the JobDefinition helloJobDef and the JobParameter[] param that are used in the method createSchedulerTask (...) go to Creating a Scheduler Task for the HelloJob .