我在我的 Java Web 应用程序上使用了quartz,但我遇到了一个奇怪的问题。我认为石英正在执行,但不要“运行” Job 任务:
我的配置文件:
石英-job.xml:
`<?xml version="1.0" encoding="ISO-8859-1"?>
<quartz xmlns="http://www.opensymphony.com/quartz/JobSchedulingData"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" overwrite-existing-jobs="true">
<job>
<job-detail>
<name>MyJob</name>
<group>DEFAULT</group>
<description>####</description>
<job-class>com.myQuartz.MyJob</job-class>
</job-detail>
<trigger>
<cron>
<name>MyTrigger</name>
<group>DEFAULT</group>
<job-name>MyJob</job-name>
<job-group>DEFAULT</job-group>
<cron-expression>0 0/5 * * * ?</cron-expression>
</cron>
</trigger>
</job>
</quartz>`
石英属性:
#===============================================================
#Configure Main Scheduler Properties
#===============================================================
org.quartz.scheduler.instanceName = QuartzScheduler
org.quartz.scheduler.instanceId = AUTO
#===============================================================
#Configure ThreadPool
#===============================================================
org.quartz.threadPool.threadCount = 3
org.quartz.threadPool.threadPriority = 5
org.quartz.threadPool.class = org.quartz.simpl.SimpleThreadPool
#===============================================================
#Configure JobStore
#===============================================================
org.quartz.jobStore.class = org.quartz.simpl.RAMJobStore
#===============================================================
#Configure Plugins
#===============================================================
org.quartz.plugin.jobInitializer.class = org.quartz.plugins.xml.JobInitializationPlugin
org.quartz.plugin.jobInitializer.overWriteExistingJobs = true
org.quartz.plugin.jobInitializer.failOnFileNotFound = false
org.quartz.plugin.jobInitializer.scanInterval = 10
org.quartz.plugin.jobInitializer.validating=false
org.quartz.plugin.jobInitializer.fileName =quartz-jobs.xml
web.xml(只需添加这个):
`<context-param>
<param-name>quartz:config-file</param-name>
<param-value>/src/quartz.properties</param-value>
</context-param>
<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>
<context-param>
<param-name>quartz:start-on-load</param-name>
<param-value>true</param-value>
</context-param>
<listener>
<listener-class>org.quartz.ee.servlet.QuartzInitializerListener</listener-class>
</listener>`
MyJob.java:
package com.myJob;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
public class MyJob implements Job {
@Override
public void execute(JobExecutionContext context){
try{
System.out.println("Quartz working!");
} catch (Exception ex){
System.out.println("not working");
}
}
}
安慰:
Quartz Initializer Servlet 已加载,正在初始化调度程序...
调度器已经启动...
将 Quartz 调度器工厂存储在 servlet 上下文中的 key 处:org.quartz.impl.StdSchedulerFactory.KEY
Quartz Scheduler 成功关机。
谢谢