Using Quartz 1.8.5 with tomcat without Spring
来源:互联网 发布:json怎么解析 编辑:程序博客网 时间:2024/05/21 04:18
在网上找了些文章来看,都是比较早的东东,有些地方的配置已经改变了,总结了一下,记录在这里。
1、从http://quartz-scheduler.org下载quartz-1.8.5.tar.gz,解压缩到目录quartz-1.8.5中
2、添加quartz-1.8.5.jar及quartz-1.8.5\lib目录中的jar文件到项目的lib目录中
3、在项目中添加对quartz-1.8.5.jar的引用
4、编写MyJob 类
import java.util.Date;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
public class MyJob implements Job{
private static Log log = LogFactory.getLog(StatServer.class);
@Override
public void execute(JobExecutionContext arg0) throws JobExecutionException {
System.out.println("Hello, " + new Date());
}
}
5、添加quartz.properties文件到classes目录中(注意红色的部分)
org.quartz.scheduler.instanceName = TestScheduler
org.quartz.scheduler.instanceId = one
org.quartz.threadPool.class = org.quartz.simpl.SimpleThreadPool
org.quartz.threadPool.threadCount = 2
org.quartz.threadPool.threadPriority = 4
org.quartz.plugin.triggHistory.class = org.quartz.plugins.history.LoggingTriggerHistoryPlugin
org.quartz.plugin.triggHistory.triggerFiredMessage = Trigger {1}.{0} fired job {6}.{5} at: {4, date, HH:mm:ss MM/dd/yyyy}
org.quartz.plugin.triggHistory.triggerCompleteMessage = Trigger {1}.{0} completed firing job {6}.{5} at {4, date, HH:mm:ss MM/dd/yyyy} with resulting trigger instruction code: {9}
org.quartz.plugin.jobInitializer.class = org.quartz.plugins.xml.XMLSchedulingDataProcessorPlugin
org.quartz.plugin.jobInitializer.fileNames = quartz_job.xml
org.quartz.plugin.jobInitializer.failOnFileNotFound = true
org.quartz.plugin.shutdownhook.class = org.quartz.plugins.management.ShutdownHookPlugin
org.quartz.plugin.shutdownhook.cleanShutdown = true
6、添加quartz_job.xml到classes目录中
<?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>MyJob1</name>
<group>jobGroup1</group>
<job-class>MyJob</job-class>
</job>
<trigger>
<cron>
<name>Trigger1</name>
<group>triggerGroup1</group>
<job-name>MyJob1</job-name>
<job-group>jobGroup1</job-group>
<cron-expression>0/5 * * * * ?</cron-expression>
</cron>
</trigger>
</schedule>
</job-scheduling-data>
7、在web.xml中添加listener
<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:start-on-load</param-name>
<param-value>true</param-value>
</context-param>
<listener>
<listener-class>
org.quartz.ee.servlet.QuartzInitializerListener
</listener-class>
</listener>
8、启动Tomcat,查看控制台输出。
- Using Quartz 1.8.5 with tomcat without Spring
- Using Quartz 1.8.5 with tomcat without Spring
- Spring+Quartz tomcat集群
- Spring+Quartz tomcat集群
- Using Flex with Spring
- using JDBC with Spring
- Using Spring Boot without the parent POM
- [转]Using SOAP with Tomcat
- [Salesforce] Using the with sharing or without sharing Keywords
- RaspiCam: C++ API for using Raspberry camera with/without OpenCv
- 浅谈java定时任务:quartz、quartz with spring
- Distributed transactions in Spring, with and without XA
- Distributed transactions in Spring, with and without XA
- using jikes without jdk
- scrollTo without using jQuery
- Spring Boot 之 Accessing Relational Data using JDBC with Spring
- Using Tomcat 6.0.x with JSF 1.2_x
- 启用Spring quartz定时器,导致tomcat服务器自动停止
- YUM常用命令详解
- 继承的构造函数的知识遗漏
- 关于hudson的问题
- 牛顿引擎教程翻译
- 用worldwind java SDK开发应用程序
- Using Quartz 1.8.5 with tomcat without Spring
- HowTo: ListView, Adapter, getView and different list items’ layouts in one ListView
- Java开发和运行环境的搭建
- maven 无法下载bundle类型的问题解决办法
- 混用ATL MFC WTL的问题-CString的冲突
- HOWTO: Customize UIKeyboard
- 12 个免费在线的 Web 网站性能测试工具
- poj 3051 Satellite Photographs 基础DFS
- Javascript调用后台方法