cron表达式是什么?cron表达式每5分钟一次 世界通讯

海外生活网
2023-07-05 08:40:41

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();

责任编辑:299
热点新闻

深圳热线 版权所有 Copyright © 2022 SZONLINE(SZONLINE.CN) All Rights Reserved.邮箱:56 26 623@qq.com

粤ICP备18025786号-54 营业执照公示信息