1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
|
public static void createScheduleJob(Scheduler scheduler, AdminQuartzDto adminQuartzDto) { try { Class<? extends Job> jobClass = (Class<? extends Job>) Class.forName(adminQuartzDto.getJobClass()); JobDetail jobDetail = JobBuilder.newJob(jobClass).withIdentity(adminQuartzDto.getJobName()).build(); CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule(adminQuartzDto.getTime()); CronTrigger trigger = TriggerBuilder.newTrigger().withIdentity(adminQuartzDto.getJobName()).withSchedule(scheduleBuilder).build(); scheduler.scheduleJob(jobDetail, trigger); } catch (ClassNotFoundException e) { log.error("定时任务类路径出错:请输入类的绝对路径"); } catch (SchedulerException e) { log.error("创建定时任务出错:" + e.getMessage()); } }
public static void pauseScheduleJob(Scheduler scheduler, String jobName) { JobKey jobKey = JobKey.jobKey(jobName); try { scheduler.pauseJob(jobKey); } catch (SchedulerException e) { log.error("暂停定时任务出错:" + e.getMessage()); } }
public static void resumeScheduleJob(Scheduler scheduler, String jobName) { JobKey jobKey = JobKey.jobKey(jobName); try { scheduler.resumeJob(jobKey); } catch (SchedulerException e) { log.error("启动定时任务出错:" + e.getMessage()); } }
public static void runOnce(Scheduler scheduler, String jobName) { JobKey jobKey = JobKey.jobKey(jobName); try { scheduler.triggerJob(jobKey); } catch (SchedulerException e) { log.error("运行定时任务出错:" + e.getMessage()); } }
public static void updateScheduleJob(Scheduler scheduler, AdminQuartzDto adminQuartzDto) { try { TriggerKey triggerKey = TriggerKey.triggerKey(adminQuartzDto.getJobName()); CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule(adminQuartzDto.getTime()); CronTrigger trigger = (CronTrigger) scheduler.getTrigger(triggerKey); trigger = trigger.getTriggerBuilder().withIdentity(triggerKey).withSchedule(scheduleBuilder).build(); scheduler.rescheduleJob(triggerKey, trigger); } catch (SchedulerException e) { log.error("更新定时任务出错:" + e.getMessage()); } }
public static void deleteScheduleJob(Scheduler scheduler, String jobName) { JobKey jobKey = JobKey.jobKey(jobName); try { scheduler.deleteJob(jobKey); } catch (SchedulerException e) { log.error("删除定时任务出错:" + e.getMessage()); } }
|