我提到了Quartz properties does not trigger Quartz Job上发现的上一个问题,并从中大量借用(作为Quartz和所有人的新手),但我的工作似乎没有解雇。
我的quartz.properties
:
org.quartz.scheduler.instanceName = MyScheduler
org.quartz.threadPool.threadCount = 3
org.quartz.jobStore.class = org.quartz.simpl.RAMJobStore
#===================================================
# Configure the Job Initialization Plugin
#===================================================
org.quartz.plugin.triggerHistory.class: org.quartz.plugins.history.LoggingTriggerHistoryPlugin
org.quartz.plugin.jobInitializer.class: org.quartz.plugins.xml.XMLSchedulingDataProcessorPlugin
org.quartz.plugin.jobInitializer.fileNames: quartz-jobs.xml
org.quartz.plugin.jobInitializer.failOnFileNotFound: true
org.quartz.plugin.jobInitializer.scanInterval: 10
org.quartz.plugin.jobInitializer.wrapInUserTransaction: false
我的quartz-job.xml
:
<?xml version='1.0' encoding='utf-8'?>
<job-scheduling-data xmlns="http://www.quartz-scheduler.org/xml/JobSchedulingData"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.quartz-scheduler.org/xml/JobSchedulingData http://www.quartz-scheduler.org/xml/job_scheduling_data_1_8.xsd"
version="1.8">
<schedule>
<job>
<name>myjob</name>
<group>MYJOBGROUP</group>
<description>Job to Test</description>
<job-class>com.mpm.epick.enotify.EmailNotifier</job-class>
</job>
<trigger>
<cron>
<name>my-trigger</name>
<group>MYTRIGGER_GROUP</group>
<job-name>myjob</job-name>
<job-group>MYJOBGROUP</job-group>
<cron-expression>* * * * * ?</cron-expression>
</cron>
</trigger>
</schedule>
</job-scheduling-data>
我在web.xml
中添加的部分:
<!-- added by ck -->
<context-param>
<param-name>quartz:config-file</param-name>
<param-value>quartz.properties</param-value>
</context-param>
<context-param>
<param-name>quartz:shutdown-on-unload</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>quartz:wait-on-shutdown</param-name>
<param-value>false</param-value>
</context-param>
<context-param>
<param-name>quartz:start-scheduler-on-load</param-name>
<param-value>true</param-value>
</context-param>
<listener>
<listener-class>org.quartz.ee.servlet.QuartzInitializerListener</listener-class>
</listener>
<servlet>
<servlet-name>QuartzInitializer</servlet-name>
<servlet-class>org.quartz.ee.servlet.QuartzInitializerServlet</servlet-class>
<init-param>
<param-name>shutdown-on-unload</param-name>
<param-value>true</param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>
<!-- end additions -->
我希望运行的类文件,`EmailNotifier'(现在它只是一个存根实现):
package com.mpm.epick.enotify;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
public class EmailNotifier implements Job {
public EmailNotifier() {}
public void execute(JobExecutionContext context) throws JobExecutionException {
System.out.println("Cron executing ");
}
}
所以我观察到我的调度程序可以正常启动/停止,如以下调试行所示:
INFO: QuartzInitializer: Scheduler has been started...
INFO: QuartzInitializer: Quartz Scheduler successful shutdown.
但是在我的控制台上我根本看不到调试行。我尝试了日志文件,但它也没有。
我错过了解雇工作的事情吗?
答案 0 :(得分:0)
我想知道这是否是因为你的cron表达式很奇怪。我不确定“* * * * *?”的意图是什么表达式,但是如果你想让它每秒开一次你应该使用“0/1 * * * *?”。有关构建cron表达式的更多信息,请参阅http://quartz-scheduler.org/documentation/quartz-2.x/tutorials/tutorial-lesson-06。