我是想用 CronTrigger
在石英调度器中,调度器正在启动,但作业没有被触发。调度器正在启动,但作业没有被触发。以下是我的代码。
SchedulerFactory factory = new StdSchedulerFactory();
Scheduler scheduler = factory.getScheduler();
DateBuilder.evenMinuteDate(new Date());
JobDetail job = JobBuilder.newJob(Sample.class).withIdentity("job1", "group1").build();
CronTrigger trigger = TriggerBuilder.newTrigger().withIdentity("trigger1", "group1")
.withSchedule(CronScheduleBuilder.cronSchedule("0 * * ? * *")).build();
scheduler.scheduleJob(job, trigger);
scheduler.start();
Sample
类代码中只有一条print语句。
当前输出如下。
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
当前版本:
<dependency>
<groupId>org.quartz-scheduler</groupId>
<artifactId>quartz</artifactId>
<version>2.3.2</version>
</dependency>
我错过了什么吗?
这是你的例子,已经实现了Sample类。
public class TestCronJob {
public static void main(String[] args) throws SchedulerException {
SchedulerFactory factory = new StdSchedulerFactory();
Scheduler scheduler = factory.getScheduler();
DateBuilder.evenMinuteDate(new Date());
JobDetail job = JobBuilder.newJob(Sample.class).withIdentity("job1", "group1").build();
CronTrigger trigger = TriggerBuilder.newTrigger().withIdentity("trigger1", "group1")
.withSchedule(CronScheduleBuilder.cronSchedule("0 * * ? * *")).build();
scheduler.scheduleJob(job, trigger);
scheduler.start();
}
public static class Sample implements Job {
@Override
public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
System.out.println("From job: " + new Date());
}
}
}
它每分钟打印一次
From job: Tue May 26 17:59:00 EEST 2020
From job: Tue May 26 18:00:00 EEST 2020
...
所以,它是按照预期工作的 在你的情况下,可能是和日志框架有关,我看到你的输出中有这样的信息。
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".