展开全部
}
import static org.quartz.CronScheduleBuilder.cronSchedule;
import static org.quartz.JobBuilder.newJob;
import static org.quartz.TriggerBuilder.newTrigger;
import 闷宏java.text.SimpleDateFormat;
import java.util.Date;
import org.quartz.CronTrigger;
import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.quartz.SchedulerFactory;
import org.quartz.impl.StdSchedulerFactory;
public class Test {
public void go() throws Exception {
// 首先,必需要取得一个Scheduler的引用
SchedulerFactory sf = new StdSchedulerFactory();
Scheduler sched = sf.getScheduler();
//jobs可以在scheduled的sched.start()方法前被调用
枯举
没罩碧 //job 1将每隔30分钟执行一次
JobDetail job = newJob(myJob.class).withIdentity("job1", "group1").build();
CronTrigger trigger = newTrigger().withIdentity("trigger1", "group1").withSchedule(cronSchedule("0 0/30 * * * ?")).build();
Date ft = sched.scheduleJob(job, trigger);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss SSS");
System.out.pintln("aa");
// 开始执行,start()方法被调用后,计时器就开始工作,计时调度中允许放入N个Job
sched.start();
try {
//主线程等待一分钟
Thread.sleep(60L * 1000L);
} catch (Exception e) {}
//关闭定时调度,定时器不再工作
sched.shutdown(true);
}
public static void main(String[] args) throws Exception {
Test test = new Test();
test.go();
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询