ниже приведен пример кода кварца (я урезаю их для упрощения, вы можете получить полный код с сайта кварца).
SimpleJob.java:
Код: Выделить всё
public class SimpleJob implements Job {
private static Logger _log = LoggerFactory.getLogger(SimpleJob.class);
public void execute(JobExecutionContext context) throws JobExecutionException {
JobKey jobKey = context.getJobDetail().getKey();
_log.info("SimpleJob says: " + jobKey + " executing at " + new Date());
}
}
Код: Выделить всё
public class CronTriggerExample {
public void run() throws Exception {
Logger log = LoggerFactory.getLogger(CronTriggerExample.class);
SchedulerFactory sf = new StdSchedulerFactory();
Scheduler sched = sf.getScheduler();
JobDetail job = newJob(SimpleJob.class)
.withIdentity("job1", "group1")
.build();
CronTrigger trigger = newTrigger()
.withIdentity("trigger1", "group1")
.withSchedule(cronSchedule("0/3 * * * * ?"))
.build();
Date ft = sched.scheduleJob(job, trigger);
log.info(job.getKey() + " has been scheduled to run at: " + ft
+ " and repeat based on expression: "
+ trigger.getCronExpression());
sched.start();
}
public static void main(String[] args) throws Exception {
CronTriggerExample example = new CronTriggerExample();
example.run();
}
}
Код: Выделить всё
public class Test1 {
@Test
public void run() throws Exception {
CronTriggerExample example = new CronTriggerExample();
example.run();
}
}
Я очень озадачен, почему тот же код не может работать в Junit?
Подробнее здесь: https://stackoverflow.com/questions/162 ... d-in-junit
Мобильная версия