执行函数
public class HessianTask implements Job{
static List<Map<Object, Object>> list = null;
NewsBaseDao newsBaseDao = null;
SuporbuyBaseDao suporbuyBaseDao = null;
ExhibationBaseDao exhibationBaseDao = null;
@Override
public void execute(JobExecutionContext content) throws JobExecutionException {
// TODO Auto-generated method stub
System.out.println(content.getTrigger().getName() + "trigger.time is"
+ new Date() + " ");
}
下面是quartz
package Cn.nwsuaf.Tasks;
import java.util.List;
import org.quartz.CronExpression;
import org.quartz.CronTrigger;
import org.quartz.JobDataMap;
import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.quartz.SchedulerFactory;
import org.quartz.impl.StdSchedulerFactory;
import Cn.nwsuaf.utils.Properties;
import Cn.nwsuaf.utils.TaskDescription;
import InformationPushMain.InformationPush;
public class QuartzTask{
/**
* @param args
*/
public static void getQuartz() {
try{
JobDetail jobDetail =null;
for(int i = 0 ; i<list.size();i++){
jobDetail = new JobDetail("job"+i, "jobGroup"+i, HessianTask.class);
CronTrigger cronTrigger = new CronTrigger("crontrigger"+i,"triggerGroup"+i);
CronExpression cronExpression = new CronExpression(list.get(quartz表达式);
cronTrigger.setCronExpression(cronExpression);
SchedulerFactory schedulefactory = new StdSchedulerFactory();
Scheduler scheduler = schedulefactory.getScheduler();
JobDataMap map = jobDetail.getJobDataMap();//在此可以传递参数的
jobDetail.setJobDataMap(map);//如果不需要传递参数不需要以上两行的
scheduler.scheduleJob(jobDetail,cronTrigger);
scheduler.start();
}
}catch(Exception e){
e.printStackTrace();
}
}
}