cron表達式是什么:
cron表達式是一個字符串,該字符串由6個空格分為7個域,每一個域代表一個時間含義。常用語定時任務。
cron表達式每5分鐘一次:
JobDetail job1 = JobBuilder.newJob(FirstJob.class).withIdentity("job1", "group1").build();
Trigger trigger1 = TriggerBuilder.newTrigger().withIdentity("cronTrigger1", "group1")
.withSchedule(CronScheduleBuilder.cronSchedule("*/10 * * * * ?")).build();
Scheduler scheduler1 = new StdSchedulerFactory().getScheduler();
scheduler1.start();
scheduler1.scheduleJob(job1, trigger1);
JobDetail job2 = JobBuilder.newJob(SecondJob.class).withIdentity("job2", "group2").build();
Trigger trigger2 = TriggerBuilder.newTrigger().withIdentity("cronTrigger2", "group2")
.withSchedule(CronScheduleBuilder.cronSchedule(new CronExpression("0/7 * * * * ?"))).build();
Scheduler scheduler2 = new StdSchedulerFactory().getScheduler();
scheduler2.start();
scheduler2.scheduleJob(job2, trigger2);
Thread.sleep(100000);
scheduler1.shutdown();
scheduler2.shutdown();