标签:except shutdown sch etl str map 参数 with info
private static String JOB_NAME = "_JOB_NAME";private static final Logger logger = LoggerFactory.getLogger(CycleRuleQuartzManager.class);
public static String addJob(Scheduler sc, String taskId, String cron) throws SchedulerException,
ClassNotFoundException {
logger.info("---------新增周期规则任务请求参数:taskId=" + taskId + ",cron=" + cron);
if (StringUtil.isEmpty(cron)) {
logger.info("addJob cron 为空");
return "0";
}
if (StringUtil.isEmpty(taskId)) {
logger.info("addJob taskId 为空");
return "0";
}
Map<String, Object> paramMap = new HashMap<String, Object>();
paramMap.put("taskId", taskId);
JobDataMap jobParam = new JobDataMap(paramMap);
JobDetail jobDetail =
JobBuilder.newJob(CycleRuleQuartzJob.class).withIdentity(taskId + JOB_NAME, JOB_GROUP_NAME)
.setJobData(jobParam).build();
TriggerBuilder<Trigger> triggerBuilder = TriggerBuilder.newTrigger();
triggerBuilder.withIdentity(taskId + TRIGGER_NAME, TRIGGER_GROUP_NAME);
triggerBuilder.startNow();
triggerBuilder.withSchedule(CronScheduleBuilder.cronSchedule(cron));
CronTrigger trigger = (CronTrigger) triggerBuilder.build();
sc.scheduleJob(jobDetail, trigger);
if (!sc.isShutdown()) {
sc.start();
}
logger.info("---------新增周期规则任务成功---------");
return "1";
}
标签:except shutdown sch etl str map 参数 with info
原文地址:https://blog.51cto.com/7218743/2487812