创建定时任务
public static void createScheduleJob(Scheduler scheduler, String jobName, String jobGroup, String cronExpression,
QrtzTaskInfo params) throws SchedulerException {
/** 任务名称、任务分组、调度表达式 */
/** 构建job信息 */
JobDetail jobDetail = JobBuilder.newJob(QuertzClusterJob.class).withIdentity(jobName, jobGroup).build();
/** 放入参数,运行时的方法可以获取 */
jobDetail.getJobDataMap().put("requestUrl", params.getRequestUrl());
jobDetail.getJobDataMap().put("requestType", params.getRequestType());
/** 表达式调度构建器 */
CronScheduleBuilder cronScheduleBuilder = CronScheduleBuilder.cronSchedule(cronExpression);
/** 按新的cronExpression表达式构建一个新的trigger */
CronTrigger trigger = TriggerBuilder.newTrigger().withIdentity(jobName, jobGroup)
.withSchedule(cronScheduleBuilder).build();
try {
scheduler.scheduleJob(jobDetail, trigger);
} catch (SchedulerException e) {
logger.error("创建定时任务失败");
throw new SchedulerException("创建定时任务失败");
}
}