点击打开链接 http://blog.csdn.net/szwangdf/article/details/6158646
需要传入参数时:
修改源代码里面的addJob方法,里面用 jobDetail.setJobDataMap(map)添加参数
public static void addJob(String jobName, String jobClass, String time , Map<String , Object> params) {
try {
Scheduler sched = gSchedulerFactory.getScheduler();
JobDetail jobDetail = new JobDetail(jobName, JOB_GROUP_NAME, Class.forName(jobClass));// 任务名,任务组,任务执行类
JobDataMap map = new JobDataMap();
map.put("xx", params.get("key1"));
map.put("x2x", params.get("key2"));
map.put("x3x", params.get("key3"));
jobDetail.setJobDataMap(map);
// 触发器
CronTrigger trigger = new CronTrigger(jobName, TRIGGER_GROUP_NAME);// 触发器名,触发器组
trigger.setCronExpression(time);// 触发器时间设定
sched.scheduleJob(jobDetail, trigger);
// 启动
if (!sched.isShutdown()){
sched.start();
}
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException(e);
}
}
execute里面取参数
public void execute(JobExecutionContext context) throws JobExecutionException {
JobDataMap map = context.getJobDetail().getJobDataMap;
}