cron表達(dá)式是什么:
cron表達(dá)式是一個(gè)字符串,該字符串由6個(gè)空格分為7個(gè)域,每一個(gè)域代表一個(gè)時(shí)間含義。常用語(yǔ)定時(shí)任務(wù)。
cron表達(dá)式每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();
標(biāo)簽: 計(jì)算機(jī)字符串 電腦表達(dá)式 定時(shí)任務(wù)常