ssc*_*zio 10 java cron quartz-scheduler
这应该是非常直接的,但我看不到任何工作被执行.我在任务的execute()方法上有一个断点,没有任何线程到达那里.我没有弄到什么问题.
工作
class Printer implements Job{
public Printer(){
System.out.println("created printer");
}
@Override
public void execute(JobExecutionContext context)
throws JobExecutionException {
System.out.println("hi" + context.getFireTime());
}
}
Run Code Online (Sandbox Code Playgroud)
主要课程
class MyClass {
public static void main(String[] args) throws Throwable {
Scheduler s = StdSchedulerFactory.getDefaultScheduler();
JobDetail job = newJob(Printer.class).build();
CronTrigger trigger =
newTrigger()
.withIdentity("a", "t")
.withSchedule(cronSchedule("0/5 * * * * ?").inTimeZone(TimeZone.getDefault()))
.forJob(job).build();
s.scheduleJob(job, trigger);
// This prints the right date!
System.out.println(trigger.getNextFireTime());
s.start();
}
}
Run Code Online (Sandbox Code Playgroud)
编辑:我发现我没有quartz.property文件,所以有可能没有创建石英线程池.因此,正如文档中所读,我使用StdSchedulerFactory替换了以下代码:
DirectSchedulerFactory.getInstance().createVolatileScheduler(10);
Scheduler s = DirectSchedulerFactory.getInstance().getScheduler();
Run Code Online (Sandbox Code Playgroud)
你猜怎么着?还没有运气.同样的效果.应用程序保持活着,触发不触发.
ssc*_*zio 14
我找到了解决方案:将定义作业(打印机)的类的可见性更改为public将使Quartz可以访问它并运行它.
public class Printer implements Job{ // just add 'public'!
public Printer(){
System.out.println("created printer");
}
@Override
public void execute(JobExecutionContext context)
throws JobExecutionException {
System.out.println("hi" + context.getFireTime());
}
}
Run Code Online (Sandbox Code Playgroud)
这是可以理解的,因为它只能传递<? extends Job>.class
给调度程序(血腥的地狱,为什么??)而不是 - 例如 - 匿名对象.
话虽如此,我发现真的很不高兴Quartz默默无法在没有单一错误消息的情况下解雇工作.
| 归档时间: |
|
| 查看次数: |
10099 次 |
| 最近记录: |