日期:2014-05-18 浏览次数:20774 次
import java.util.Date;
import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.SchedulerFactory;
import org.quartz.SimpleTrigger;
import org.quartz.impl.StdSchedulerFactory;
public class TestTwo {
/**
* @param args
*/
public static void main(String[] args) {
try {
SchedulerFactory sf = new StdSchedulerFactory();
Scheduler sched = sf.getScheduler();
JobDetail job = new JobDetail();
job.setJobClass(HelloJob.class);
job.setGroup("jobgourp");
job.setName("jobname");
SimpleTrigger striger=new SimpleTrigger();
striger.setName("strigername");
striger.setStartTime(new Date());
striger.setRepeatInterval(1000);
striger.setRepeatCount(-1);
striger.setJobName("jobname");
striger.setJobGroup("jobgourp");
sched.scheduleJob(job, striger);
sched.start();
//-------------------------------------------------------
Thread.sleep(4000);
System.out.println("暂停");
sched.pauseJobGroup("jobgourp");
sched.pauseTriggerGroup("jobgourp");
Thread.sleep(5000);
System.out.println("暂停结束");
sched.resumeJobGroup("jobgourp");
sched.resumeTriggerGroup("jobgourp");
sched.start();
Thread.sleep(4800);
sched.shutdown(true);
} catch (SchedulerException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
package com.scy.quartz.test;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
public class HelloJob implements Job {
@Override
public void execute(JobExecutionContext arg0) throws JobExecutionException {
System.out.println("HelloJob 执行了"+new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").format(new Date()));
}
}