我想每周一上午9点执行一个任务,所以我使用的是Quartz,但是我在Java项目中遇到了一些问题。我在网上看过一些tuto,但没有一个对我有用。这就是我所做的:
quartz.properties
# Configuring Main Scheduler Properties
org.quartz.scheduler.instanceName = TriggerQuartz
org.quartz.scheduler.instanceId = 1
org.quartz.scheduler.rmi.export = false
org.quartz.scheduler.rmi.proxy = false
# Configuring ThreadPool
org.quartz.threadPool.class = org.quartz.simpl.SimpleThreadPool
org.quartz.threadPool.threadCount = 30
org.quartz.threadPool.threadPriority = 5
org.quartz.plugin.jobInitializer.class=org.quartz.plugins.xml.XMLSchedulingDataProcessorPlugin
TriggerQuartz.java
package servlet;
import org.quartz.CronScheduleBuilder;
import org.quartz.JobBuilder;
import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.quartz.Trigger;
import org.quartz.TriggerBuilder;
import org.quartz.impl.StdSchedulerFactory;
public class TriggerQuartz
{
public static void main( String[] args ) throws Exception
{
JobDetail job = JobBuilder.newJob(DHTask.class)
.withIdentity("dummyJobName", "group1").build();
Trigger trigger = TriggerBuilder
.newTrigger()
.withIdentity("dummyTriggerName", "group1")
.withSchedule(
CronScheduleBuilder.cronSchedule(" 0 0 9 ? * MON *"))
.build();
Scheduler scheduler = new StdSchedulerFactory().getScheduler();
scheduler.start();
scheduler.scheduleJob(job, trigger);
}
}
DHTask.java
package servlet;
import org.quartz.*;
public class DHTask implements Job
{
DHData data = new DHData();
DHDemande d = new DHDemande();
public void execute(JobExecutionContext context)
throws JobExecutionException {
System.out.println("Task done!");
}
}
我错过了什么?