org.quartz.CronScheduleBuilder; org.quartz.CronTrigger; org.quartz.JobBuilder; org.quartz.JobDetail; org.quartz.JobKey; org.quartz.Scheduler; org.quartz.SchedulerException; org.quartz.SchedulerFactory; org.quartz.Trigger; org.quartz.TriggerBuilder; org.quartz.TriggerKey; org.quartz.impl.StdSchedulerFactory; { SchedulerFactory schedulerFactory StdSchedulerFactory(); () addJob( jobName, groupName, triggerGroupName, Class jobClass, cronExpression) { Scheduler scheduler; { scheduler schedulerFactory.getScheduler(); JobDetail jobDetail JobBuilder.newJob(jobClass).withIdentity(jobName, groupName).build(); Trigger trigger TriggerBuilder.newTrigger().startNow().withIdentity(jobName, triggerGroupName).withSchedule(CronScheduleBuilder.cronSchedule(cronExpression)).build(); scheduler.scheduleJob(jobDetail, trigger); (scheduler.isShutdown()) { scheduler.start(); } } (SchedulerException e) { e.printStackTrace(); } } () addJob( jobName, groupName, triggerName, triggerGroupName, Class jobClass, cronExpression) { Scheduler scheduler; { scheduler schedulerFactory.getScheduler(); JobDetail jobDetail JobBuilder.newJob(jobClass).withIdentity(jobName, groupName).build(); Trigger trigger TriggerBuilder.newTrigger().startNow().withIdentity(triggerName, triggerGroupName).withSchedule(CronScheduleBuilder.cronSchedule(cronExpression)).build(); scheduler.scheduleJob(jobDetail, trigger); (scheduler.isShutdown()) { scheduler.start(); } } (SchedulerException e) { e.printStackTrace(); } } modifyJobTime( triggerName, triggerGroupName, newCronExpression) { { Scheduler scheduler schedulerFactory.getScheduler(); CronTrigger trigger (CronTrigger) scheduler.getTrigger( TriggerKey(triggerName,triggerGroupName)); (trigger ) { ; } cronExpression trigger.getCronExpression(); (cronExpression.equalsIgnoreCase(newCronExpression)) { Trigger newTrigger TriggerBuilder.newTrigger().startNow().withIdentity(triggerName, triggerGroupName).withSchedule(CronScheduleBuilder.cronSchedule(newCronExpression)).build(); scheduler.rescheduleJob( TriggerKey(triggerName,triggerGroupName), newTrigger); } } (SchedulerException e) { e.printStackTrace(); } } removeJob( jobName, jobGroupName, triggerName, triggerGroupName) { { Scheduler scheduler schedulerFactory.getScheduler(); scheduler.pauseTrigger( TriggerKey(triggerName, triggerGroupName)); scheduler.unscheduleJob( TriggerKey(triggerName, triggerGroupName)); scheduler.pauseJob( JobKey(jobName, jobGroupName)); scheduler.deleteJob( JobKey(jobName, jobGroupName)); } (SchedulerException e) { e.printStackTrace(); } } startJobs() { { Scheduler scheduler schedulerFactory.getScheduler(); scheduler.start(); } (SchedulerException e) { e.printStackTrace(); } } shutdownJobs() { { Scheduler scheduler schedulerFactory.getScheduler(); (scheduler.isShutdown()) { scheduler.shutdown(); } } (SchedulerException e) { e.printStackTrace(); } } }