我有一堂课,我在其中执行一些活动,并且我想创建一个可以自动处理此操作的作业,例如,每x分钟安排一次。我正在使用Quartz,此类实现Job,在驱动程序类中,我将创建Jobdetail,Scheduler和Trigger,然后启动它。但是,该作业未执行,日志信息:
NOT STARTED.
Currently in standby mode.
Number of jobs executed: 0
我的驱动程序类中调度程序的代码:
try {
JobDetail job = JobBuilder.newJob(TestMkFPMJob.class).withIdentity("TestMkFPMJob").build();
Trigger trigger = TriggerBuilder.newTrigger().withSchedule(SimpleScheduleBuilder.simpleSchedule().withIntervalInSeconds(Integer.parseInt(strTimeSched)).repeatForever()).build();
SchedulerFactory schFactory = new StdSchedulerFactory();
Scheduler sch = schFactory.getScheduler();
sch.start();
sch.scheduleJob(job, trigger);
}
catch (SchedulerException e)
{
e.printStackTrace();
System.out.println("Scheduler Error");
}
[“ TestMkFPMJob”是处理我的操作的作业类,并且已经获取了strTimeSched并将其设置为从以下位置获取的120
我一直在寻找类似的问题,但似乎找不到前进的小窍门,不胜感激。请注意,这是我第一次使用Quartz / Job计划。
带有NOT STARTED
的日志条目具有误导性,如创建QuartzScheduler
实例时显示的那样。这并不意味着作业没有运行。
如果我以您的示例为例,并在我的PC上运行它,则它按设计的方式工作:
public class Quartz {
public static void main(String[] args) {
try {
JobDetail job = JobBuilder.newJob(MyJob.class).withIdentity("myJob").build();
Trigger trigger = TriggerBuilder.newTrigger().withSchedule(SimpleScheduleBuilder.simpleSchedule().withIntervalInSeconds(Integer.parseInt("10")).repeatForever()).build();
SchedulerFactory schFactory = new StdSchedulerFactory();
Scheduler sch = schFactory.getScheduler();
sch.start();
sch.scheduleJob(job, trigger);
}
catch (SchedulerException e)
{
e.printStackTrace();
System.out.println("Scheduler Error");
}
}
public static class MyJob implements Job {
@Override
public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
System.out.println("runnning job");
}
}
}