cron表达式
怎么和cron表达式结合一起使用?
怎么和cron表达式结合一起使用?
2019-05-27
QuartzEntity quartz = new QuartzEntity(); quartz.setJobName("monitor_addNesToES"); quartz.setJobGroup("monitor"); quartz.setDescription("定时向ES中更新数据"); quartz.setJobClassName("com.jin.quartztask.job.AddNewsToEsJob"); quartz.setCronExpression("0 0 8/1 * * ?"); Class cls = Class.forName(quartz.getJobClassName()) ; cls.newInstance(); //构建job信息 JobDetail job = JobBuilder.newJob(cls).withIdentity(quartz.getJobName(), quartz.getJobGroup()) .withDescription(quartz.getDescription()).build(); //添加JobDataMap数据 *//*job.getJobDataMap().put("itstyle", "欢迎你"); job.getJobDataMap().put("blog", "https://www.xxx.com"); job.getJobDataMap().put("data", new String[]{"张三","李四"});*//* // 触发时间点 CronScheduleBuilder cronScheduleBuilder = CronScheduleBuilder.cronSchedule(quartz.getCronExpression()); Trigger trigger = TriggerBuilder.newTrigger().withIdentity("trigger"+quartz.getJobName(), quartz.getJobGroup()) .startNow().withSchedule(cronScheduleBuilder).build(); //交由Scheduler安排触发 scheduler.scheduleJob(job, trigger);
举报