public class CustomJobServiceImpl extends SimpleServiceComponent implements CustomJobService, ConfigurationManagementListener {
// The scheduler service, injected by the framework
private SchedulerService mySchedulerService = null;
// Name of the job
private static String JOBNAME = WCBConstants.WCB_ID + “scheduled job”;
public void onStart() {
scheduleJob();
}
public void onStop() {
myConfigurationManagement.removeListener(this);
unscheduleJob();
}
here
public void run(SchedulerJob job) {
}
privatepublic void scheduleJobrun(SchedulerJob job) {
// Check whether this instance is the cluster task master
SchedulerJob job =if mySchedulerService(!myFrameworkConfig.getSchedulerJobisClusterTaskMaster();) {
jobLOG.setServiceInterfaceNamelog(CustomJobService.class.getName());
job.setMethodName("run");
job.setName(JOBNAME);
job.setSchedule("0 0/15 * * * ?");
job.setAllowConcurrentRuns(false);
mySchedulerService.addSchedulerJob(job);
Level.INFO, "Execution of job '" + JOB_NAME + "' skipped on this server.");
return;
}
// First create a session.
try (Session session = mySessionManager.createSession(myConfigUtil.getWebsiteId(), myConfigUtil.getUsername())) {
LOG.log(Level.INFO, "Execution of job '" + JOB_NAME + "' started.");
LOG.log(Level.INFO, "Hi " + session.getContext().getUsername());
LOG.log(Level.INFO, "Execution of job '" + JOB_NAME + "' finished.");
}
}
}
|