Мои задания не выполняются.
Я использую кварц версии 2.1.1, а мой сервлет - tomcat.Я должен запускать задания, когда там настройки написаны в triggers_jobs.xml.Файл выглядит следующим образом:
<?xml version='1.0' encoding='utf-8'?>
<quartz>
<job>
<job-detail>
<name>my_job1</name>
<group>my_group</group>
<job-class>com.crossreader.webapi.scheduler.ScheduledTasksJob</job-class>
</job-detail>
<trigger>
<cron>
<name>dailyTrigger</name>
<group>my_group</group>
<job-name>my_job1</job-name>
<job-group>my_group</job-group>
<!-- trigger that fires every 5 minutes -->
<cron-expression>0 0/5 * * * _</cron-expression>
</cron>
</trigger>
</job>
</quartz>
Я создал сервлет, который выглядит следующим образом:
public class SchedulerServlet extends GenericServlet {
static private final CRLogger LOG = CRLogger.createCRLogger();
public void init(ServletConfig servletConfig) throws ServletException {
super.init(servletConfig);
try{
LOG.info("........ Start SchedulerManager ..............");
// Grab the Scheduler instance from the Factory
SchedulerFactory schedulerFactory = new StdSchedulerFactory();
final Scheduler scheduler = schedulerFactory.getScheduler();
// start the scheduler
scheduler.start();
} catch(SchedulerException e) {
e.printStackTrace();
}
}
}
И я создал класс ScheduledTasksJob, который наследуется от Job, и выглядит это так:
public class ScheduledTasksJob implements Job{
public ScheduledTasksJob() {
LOG.info("........ ScheduledTasksJob Starts - constructor ..............");
}
public void execute(JobExecutionContext context) throws JobExecutionException {
try{
MyServletClass.runAllJobs();
} catch(Exception e) {
e.printStackTrace();
}
}
}
Это мой файл quartz.properties:
# This scheduler's name will be "MyQuartzScheduler"
org.quartz.scheduler.instanceName: MyQuartzScheduler
org.quartz.scheduler.instanceId = AUTO
org.quartz.scheduler.rmi.export: false
org.quartz.scheduler.rmi.proxy: false
org.quartz.threadPool.class: org.quartz.simpl.SimpleThreadPool
# There are 3 threads in the thread pool, which means that a maximum of 3 jobs can be run simultaneously.
org.quartz.threadPool.threadCount: 3
# All of Quartz's data, such as details of jobs and triggers, is held in memory (rather than in a database).
org.quartz.jobStore.class: org.quartz.simpl.RAMJobStore
org.quartz.plugin.jobInitializer.class = org.quartz.plugins.xml.JobInitializationPlugin
org.quartz.plugin.jobInitializer.fileName = jobs/triggers_jobs.xml
org.quartz.plugin.jobInitializer.overWriteExistingJobs = true
org.quartz.plugin.jobInitializer.failOnFileNotFound = true
Это то, что я получаю в файле LOG:
INFO: QuartzInitializer: Quartz Initializer Servlet loaded, initializing Scheduler...
[11:38:10] [hread-1] [INFO] [StdSchedulerFactory] > Using default implementation for ThreadExecutor
[11:38:10] [hread-1] [INFO] [SimpleThreadPool] > Job execution threads will use class loader of thread: pool-2-thread-1
[11:38:10] [hread-1] [INFO] [SchedulerSignalerImpl] > Initialized Scheduler Signaller of type: class org.quartz.core.SchedulerSignalerImpl
[11:38:10] [hread-1] [INFO] [QuartzScheduler] > Quartz Scheduler v.2.1.1 created.
[11:38:10] [hread-1] [INFO] [RAMJobStore] > RAMJobStore initialized.
[11:38:10] [hread-1] [INFO] [QuartzScheduler] > Scheduler meta-data: Quartz Scheduler (v2.1.1) 'DefaultQuartzScheduler' with instanceId 'NON_CLUSTERED'
Scheduler class: 'org.quartz.core.QuartzScheduler' - running locally.
NOT STARTED.
Currently in standby mode.
Number of jobs executed: 0
Using thread pool 'org.quartz.simpl.SimpleThreadPool' - with 10 threads.
Using job-store 'org.quartz.simpl.RAMJobStore' - which does not support persistence. and is not clustered.
[11:38:10] [hread-1] [INFO] [StdSchedulerFactory] > Quartz scheduler 'DefaultQuartzScheduler' initialized from default resource file in Quartz package: 'quartz.properties'
[11:38:10] [hread-1] [INFO] [StdSchedulerFactory] > Quartz scheduler version: 2.1.1
[11:38:10] [hread-1] [INFO] [QuartzScheduler] > Scheduler DefaultQuartzScheduler_$_NON_CLUSTERED started.
[11:38:10] [rThread] [DEBUG] [QuartzSchedulerThread] > batch acquisition of 0 triggers
??? 22, 2012 11:38:10 AM org.apache.catalina.core.ApplicationContext log
INFO: QuartzInitializer: Scheduler has been started...
??? 22, 2012 11:38:10 AM org.apache.catalina.core.ApplicationContext log
INFO: QuartzInitializer: Storing the Quartz Scheduler Factory in the servlet context at key: org.quartz.impl.StdSchedulerFactory.KEY
[11:38:10] [hread-1] [INFO] [SchedulerManager] > ........ Start SchedulerManager ..............
[11:38:10] [hread-1] [INFO] [QuartzScheduler] > Scheduler DefaultQuartzScheduler_$_NON_CLUSTERED started.
[11:38:10] [rThread] [DEBUG] [QuartzSchedulerThread] > batch acquisition of 0 triggers
??? 22, 2012 11:38:10 AM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-8080"]
??? 22, 2012 11:38:10 AM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-bio-8009"]
??? 22, 2012 11:38:10 AM org.apache.catalina.startup.Catalina start
INFO: Server startup in 25379 ms
Connected to server
[11:38:11] [Timer-0] [DEBUG] [UpdateChecker] > Checking for available updated version of Quartz...
[11:38:12] [Timer-0] [INFO] [UpdateChecker] > New Quartz update(s) found: 2.1.2 [http://www.terracotta.org/kit/reflector?kitID=default&pageID=QuartzChangeLog]
[11:38:34] [rThread] [DEBUG] [QuartzSchedulerThread] > batch acquisition of 0 triggers
.
.
.
[11:44:46] [rThread] [DEBUG] [QuartzSchedulerThread] > batch acquisition of 0 triggers
Почему класс ScheduledTasksJob notработает?
Спасибо за помощь.