This Service functions as a wrapper around the Quartz Scheduler. It is written for use in any Avalon compatible container.


Scheduled jobs can be either created programmatically (using the Quartz API) or by using an XML configuration based on the 'XMLSchedulingDataProcessorPlugin'. A scheduled job consists of a class implementing the interface org.quartz.Job This requires just that one method be defined, execute(), whose org.quartz.JobExecutionContext argument provides you with details of the execution context when the task is triggered.

import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;

public class SimpleJob implements Job
  public static boolean executed = false;

  public SimpleJob()

  public void execute(JobExecutionContext context)
    throws JobExecutionException
    executed = true;

In order to invoke the SimpleJob we have to tell Quartz when to invoke the 'execute' method. In this case we create a CRON trigger firing every second to invoke SimpleJob#execute() on a newly created instance. Please note that we define a set of parameters using the <job-data-map> which are available using 'JobExecutionContext'.

    <description>A simple job</description>
      <!-- define a Cron trigger firing every second -->
      <cron-expression>* * * * * ?</cron-expression>


Implementation Details

The implementation registers a JobListener which intercepts the execution of the job to set some Avalon infrastructure such 'Logger' and 'ServiceManager'. This allows an simple invocation of an Avalon service within the job execution.

On shutdown the service implementation ensures that all currently executed jobs are finished. This avoids problems if a scheduled job tries to access already disposed services.

The service can be started without quartz configuration (relying on default settings) and preconfigured triggers.