Scheduled Jobs

A common requirement of workflow applications is to periodically execute certain logic according to a set schedule. MDW provides the ScheduledJob interface, which you can implement for this purpose. The run() method in your ScheduledJob implementation is invoked according to a scheduled spelled out in your MDW properties file. The syntax for scheduling is similar to that of the familiar cron utility. Here's an example:

mdw.timer.task.ProcessCleanup.TimerClass=com.centurylink.mdw.timer.cleanup.ProcessCleanup
# run every day at 2:30 a.m.
mdw.timer.task.ProcessCleanup.Schedule=30 2 * * ? *

This example shows the scheduling of the MDW-provided Process Cleanup job to remove old runtime instances. The value for the first property is the fully-qualified scheduled job class name, and the second property defines the schedule.

Job Execution

MDW guarantees that your scheduled job will run exactly once per scheduled interval at the designated time. We take appropriate locking precautions to prevent multiple server instances in your clustered environment from racing each other to execute the job. By default, it's undefined which server instance will pick up the job (in practice it's common that the same instance ends up always running the job). MDW provides the RoundRobinScheduledJob strategy. If your ScheduledJob implementation extends this base class, then you'll get simple round-robin balancing for free. If you need a more customized approach, then you can extend LoadBalancedScheduledJob to implement your own distribution logic.

Job Arguments

Use of job arguments is illustrated by another MDW built-in ScheduledJob implementation, ScheduledProcessStart. Example usage:

# launch MyWorkflowProcess every day at 10:45
mdw.timer.task.MyProcessJob.TimerClass=com.centurylink.mdw.timer.process.ScheduledProcessStart?ProcessName=com.centurylink.mypackage.MyWorkflowProcess
mdw.timer.task.MyProcessJob.Schedule=45 10 * * ? *

The argument name/value here is ProcessName=com.centurylink.mypackage.MyWorkflowProcess. Arguments are appended to the scheduled job registration property in a form like URL request parameters. These arguments are made available to your run() method via its CallURL parameter. The CallURL class provides methods such as getParameter() for retrieving the designated values.