Source:
public void scheduleJob(CronTaskConfigurationDto cronTaskConfiguration) { String jobClassName = cronTaskConfiguration.getJobClass(); Class<? extends Job> jobClass; try { jobClass = (Class<? extends Job>) Class.forName(jobClassName); } catch (ClassNotFoundException e) { logger.error("Failed to schedule cron job [{}]", jobClassName, e); return; } deleteJob(cronTaskConfiguration.getUuid()); JobDataMap jobDataMap = new JobDataMap(); jobDataMap.put("config", cronTaskConfiguration); JobKey jobKey = JobKey.jobKey(cronTaskConfiguration.getUuid().toString()); JobDetail jobDetail = JobBuilder.newJob(jobClass) .withIdentity(jobKey) .setJobData(jobDataMap) .storeDurably() .build(); try { scheduler.addJob(jobDetail, true); logger.debug("Job '{}' added to the Scheduler.", cronTaskConfiguration.getUuid()); } catch (SchedulerException e) { logger.error("Failed to add Cron Job to the Scheduler", cronTaskConfiguration, e); return; } boolean scheduleJob = true; if (cronTaskConfiguration.shouldExecuteImmediately()) { try { scheduler.triggerJob(jobKey); logger.debug("Job '{}' triggered by the Scheduler.", cronTaskConfiguration.getUuid()); } catch (SchedulerException e) { logger.error("Failed to trigger Cron Job by the Scheduler", cronTaskConfiguration, e); return; } scheduleJob = !cronTaskConfiguration.isOneTimeExecution(); } if (!scheduleJob) { logger.debug("Job '{}' won't be scheduled based on the cron expression.", cronTaskConfiguration.getUuid()); return; } TriggerKey triggerKey = TriggerKey.triggerKey(cronTaskConfiguration.getUuid().toString()); TriggerBuilder<Trigger> triggerBuilder = TriggerBuilder.newTrigger() .withIdentity(triggerKey) .forJob(jobDetail); String cronExpression = cronTaskConfiguration.getCronExpression(); triggerBuilder.withSchedule(CronScheduleBuilder.cronSchedule(cronExpression)); Trigger trigger = triggerBuilder.build(); try { scheduler.scheduleJob(trigger); logger.debug("Job '{}' scheduled.", cronTaskConfiguration.getUuid()); } catch (SchedulerException e) { logger.error("Failed to schedule Cron Job:\n [{}]", cronTaskConfiguration, e); return; } }

Target:
public void scheduleJob(CronTaskConfigurationDto cronTaskConfiguration) { String jobClassName = cronTaskConfiguration.getJobClass(); Class<? extends Job> jobClass; try { jobClass = (Class<? extends Job>) Class.forName(jobClassName); } catch (ClassNotFoundException e) { logger.error("Failed to schedule cron job [{}]", jobClassName, e); return; } deleteJob(cronTaskConfiguration.getUuid()); JobDataMap jobDataMap = new JobDataMap(); jobDataMap.put("config", cronTaskConfiguration); JobKey jobKey = JobKey.jobKey(cronTaskConfiguration.getUuid().toString()); JobDetail jobDetail = JobBuilder.newJob(jobClass) .withIdentity(jobKey) .setJobData(jobDataMap) .storeDurably() .build(); try { scheduler.addJob(jobDetail, true); logger.debug("Job '{}' added to the Scheduler.", cronTaskConfiguration.getUuid()); } catch (SchedulerException e) { logger.error("Failed to add Cron Job to the Scheduler", cronTaskConfiguration, e); return; } boolean scheduleJob = true; if (cronTaskConfiguration.shouldExecuteImmediately()) { try { scheduler.triggerJob(jobKey); logger.debug("Job '{}' triggered by the Scheduler.", cronTaskConfiguration.getUuid()); } catch (SchedulerException e) { logger.error("Failed to trigger Cron Job by the Scheduler", cronTaskConfiguration, e); return; } scheduleJob = !cronTaskConfiguration.isOneTimeExecution(); } if (!scheduleJob) { logger.debug("Job '{}' won't be scheduled based on the cron expression.", cronTaskConfiguration.getUuid()); return; } TriggerKey triggerKey = TriggerKey.triggerKey(cronTaskConfiguration.getUuid().toString()); TriggerBuilder<Trigger> triggerBuilder = TriggerBuilder.newTrigger() .withIdentity(triggerKey) .forJob(jobDetail); String cronExpression = cronTaskConfiguration.getCronExpression(); triggerBuilder.withSchedule(CronScheduleBuilder.cronSchedule(cronExpression)); Trigger trigger = triggerBuilder.build(); try { scheduler.scheduleJob(trigger); logger.debug("Job '{}' scheduled.", cronTaskConfiguration.getUuid()); } catch (SchedulerException e) { logger.error("Failed to schedule Cron Job: [{}]", cronTaskConfiguration, e); return; } }