首页>数码 > 正文
cron表达式是什么?cron表达式每5分钟一次
来源: 海外生活网 发布于:2023-07-05 09:04:14

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

关键词: 计算机字符串 电脑表达式 定时任务常用语 时间含义

猜你喜欢