Quartz定时器 报错
下面的程序我是放在Servlet init() 方法里面运行的。我引用的是quartz-all-1.6.0.jar。
程序运行报错
2013-9-29 16:00:07 org.apache.catalina.core.ApplicationContext log
严重: StandardWrapper.Throwable
java.lang.InstantiationError: org.quartz.JobDetail
at servlet.UniversalQuartzManager.start(UniversalQuartzManager.java:43)
......
请各位帮我解决一下,本人新手,越详细越好,谢谢!!!!
程序如下:
package servlet;
import java.text.ParseException;
import java.util.Date;
import org.quartz.CronTrigger;
import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.SchedulerFactory;
import org.quartz.impl.StdSchedulerFactory;
public class UniversalQuartzManager {
private static UniversalQuartzManager instance = null;
private Scheduler sched = null;
private SchedulerFactory factory = null;
private UniversalQuartzManager() {
_init();
}
private void _init() {
factory = new StdSchedulerFactory();
try {
sched = factory.getScheduler();
} catch (SchedulerException e) {
e.printStackTrace();
}
}
public synchronized static UniversalQuartzManager getInstance() {
if (instance == null) {
instance = new UniversalQuartzManager();
}
return instance;
}
public void start() {
try {
sched.start();
// 在这里加载需要执行的业务逻辑类UniversalQuartz.class
JobDetail detail = new JobDetail("cmhksynchron", "cmhkSynch",UniversalQuartz.class);
CronTrigger trigger = new CronTrigger();
// 手动添加了时间
System.out.println("UniversalQuartzManager");
trigger.setCronExpression("2 * * * * ?");
// trigger.setCronExpression("0 0-59 16 * * ?");
trigger.setName("abintrigger");
trigger.setStartTime(new Date());
sched.scheduleJob(detail, trigger);
} catch (SchedulerException e) {
e.printStackTrace();
} catch (ParseException e2) {
e2.printStackTrace();
}
}
public void stop() {
try {
sched.shutdown();
sched = factory.getScheduler();
} catch (SchedulerException e) {
e.printStackTrace();
}
}
public void refresh() {
// 未知的原因,程序执行这段判断进入stop(),在sched.shutdown();这一句报错,//所以暂时将其屏蔽,以待后来解决
// try {
// if(sched != null && sched.isStarted()) {
// this.stop();
// }
this.start();
// } catch (SchedulerException e) {
// e.printStackTrace();
// }
}
}