Quartz 1.8.5

2014-11-24 08:36:41 · 作者: · 浏览: 0

首先编写Job类,只需要实现Job接口
[html]
import java.util.Date;

import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;

public class MyFirstQuartz implements Job {

public void execute(JobExecutionContext arg0) throws JobExecutionException {
// TODO Auto-generated method stub
System.out.println(arg0.getJobRunTime());
System.out.println(arg0.hashCode());
System.out.println(arg0.getTrigger().getGroup());
System.out.println(arg0.getTrigger().getName());
System.out.println("Hello world");

}
public void test(){
System.out.println("xxxxxxxxxxxxxxxxxxxxx"+new Date().getTime());
}
}


quartz_jobs.xml:
[html]
< xml version="1.0" encoding="UTF-8" >
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">


hello
group
org.han.quartz.MyFirstQuartz



trigger
group
hello
group
0/5 * * * *



quartz.properties:
#===============================================================
#Configure Main Scheduler Properties
#===============================================================
org.quartz.scheduler.instanceName = QuartzScheduler
org.quartz.scheduler.instanceId = AUTO

#===============================================================
#Configure ThreadPool
#===============================================================
org.quartz.threadPool.threadCount = 5
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.XMLSchedulingDataProcessorPlugin

org.quartz.plugin.jobInitializer.fileNames = quartz_jobs.xml
org.quartz.plugin.jobInitializer.failOnFileNotFound = true
org.quartz.plugin.shutdownhook.class = org.quartz.plugins.management.ShutdownHookPlugin
org.quartz.plugin.shutdownhook.cleanShutdown =true

最后记得在web.xml进行配置:
[html]


QuartzInitializer


org.quartz.ee.servlet.QuartzInitializerServlet


config-file
/quartz.properties


shutdown-on-unload
true

1

当web容器启动的时候Quartz也开始运作了
作者:hanzhou4519