Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Added concurrent runs

...

Code Block
themeEclipse
public class CustomJobServiceImpl extends SimpleServiceComponent implements CustomJobService {
	// The scheduler service, injected by the framework
	private SchedulerService mySchedulerService = null;

	// Name of the job
	private static String JOBNAME = WCBConstants.WCB_ID + “custom job”;

	public void onStart() {
		scheduleJob();
	}

	  public void onStop() {
		  mySchedulerService.removeSchedulerJob(JOBNAME);  }

	public void run(SchedulerJob job) {
	}

	private void scheduleJob() {  
	    SchedulerJob job = mySchedulerService.getSchedulerJob();
 		job.setServiceInterfaceName(CustomJobService.class.getName());
		job.setMethodName("run");
		job.setName(JOBNAME);
		job.setSchedule("0 0/15 * * * ?");
        job.setAllowConcurrentRuns(false);
		mySchedulerService.addSchedulerJob(job);
	}
}

...

Using the code example above, the run method will be invoked every 15 minutes. Concurrent runs is disabled, so if the run method takes longer than 15 minutes, the next job will not be run. The name of the job is subject to the guidelines since only one job can use a certain name. Guideline G151 defines that this name must be prefixed by the plugin ID.

...

The implementation of the ConfigurationManagementListener can register itself on changes in the configuration set that contain the schedule and reschedule the job when there is a  change.

 

Back to Top

 

...

 

Concurrent runs

By default jobs will run concurrently; the run method may be invoked again by another thread before the the previous run has completed. Concurrent runs can be disabled on the SchedulerJob instance.

 

Back to Top