@Override public void execute(Map<String, Object> jobDataMap) { JobId jobId = (JobId) jobDataMap.get(KEY_JOB_ID); JobConfig jobConfig = (JobConfig) jobDataMap.get(KEY_JOB_CONFIG); FallbackSchedulerService scheduler = (FallbackSchedulerService) jobDataMap.get(KEY_SCHEDULER_SERVICE); JobRunner runner = scheduler.getJobRunner(jobConfig.getJobRunnerKey()); if (runner != null) { runner.runJob(new SimpleRunnerJobRequest(jobId, jobConfig)); } } }
@Nonnull private JobRunnerResponse runJob() { final RunningJob job = new RunningJobImpl(firedAt, jobId, jobConfig); final RunningJob existing = schedulerService.enterJob(jobId, job); if (existing != null) { LOG.debug("Unable to start job {} because it is already running as {}", job, existing); return JobRunnerResponse.aborted("Already running"); } schedulerService.preJob(); final Thread thd = Thread.currentThread(); final ClassLoader originalClassLoader = thd.getContextClassLoader(); try { // SCHEDULER-11: Ensure that the Job runs with its own class loader set as the thread's CCL thd.setContextClassLoader(jobRunner.getClass().getClassLoader()); final JobRunnerResponse response = jobRunner.runJob(job); return (response != null) ? response : JobRunnerResponse.success(); } finally { thd.setContextClassLoader(originalClassLoader); schedulerService.leaveJob(jobId, job); schedulerService.postJob(); } }