packagecom.imooc.demo.HelloQuartz;
importjava.text.SimpleDateFormat;
importjava.util.Date;
importorg.quartz.CronScheduleBuilder;
importorg.quartz.CronTrigger;
importorg.quartz.JobBuilder;
importorg.quartz.JobDetail;
importorg.quartz.Scheduler;
importorg.quartz.SchedulerException;
importorg.quartz.SchedulerFactory;
importorg.quartz.TriggerBuilder;
importorg.quartz.impl.StdSchedulerFactory;
publicclassHelloScheduler {
publicstaticvoidmain(String[] args) throwsSchedulerException, InterruptedException {
Datedate=newDate();
SimpleDateFormatsf=newSimpleDateFormat("yyyy-MM-dd HH:mm:ss");
System.out.println("Current Time Is : "+sf.format(date));
JobDetailjobDetail=JobBuilder.newJob(HelloJob.class)
.withIdentity("myJob").build();
CronTriggertrigger= (CronTrigger) TriggerBuilder .newTrigger()
.withIdentity("myTrigger", "group1")
.withSchedule(
CronScheduleBuilder.cronSchedule("* * * * * ?"))
.build();
SchedulerFactorysfact=newStdSchedulerFactory();
Schedulerscheduler=sfact.getScheduler();
scheduler.start();
System.out.println("scheduled time is :"+sf.format(scheduler.scheduleJob(jobDetail, trigger)));
Thread.sleep(2000L);
scheduler.shutdown(false);
System.out.println("scheduler is shut down? "+scheduler.isShutdown());
}
}