private static String JOB_NAME = "_JOB_NAME";
private static String JOB_GROUP_NAME = "EXTJWEB_JOBGROUP_NAME";
private static String TRIGGER_NAME = "_TRIGGER" + "_NAME";
private static String TRIGGER_GROUP_NAME = "EXTJWEB_TRIGGERGROUP_NAME";ide
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"; }