qinyubin

导航

Quartz之主方法运行

 1 import static org.quartz.JobBuilder.newJob;
 2 import static org.quartz.TriggerBuilder.newTrigger;  
 3 import static org.quartz.CronScheduleBuilder.*;
 4 
 5 import org.apache.log4j.Logger;
 6 import org.quartz.JobDetail;
 7 import org.quartz.Scheduler;
 8 import org.quartz.SchedulerFactory;
 9 import org.quartz.Trigger;
10 
11 import com.htt.speed.util.CommonUtils;
12 
13 public class HttSpeedUploadMain {
14     private static Logger logger = Logger.getLogger(HttSpeedUploadMain.class);
15 
16     public static void main(String[] args) {
17         try {
18             logger.info("上传主程序运行......");
19             String cronExpression = CommonUtils.getCornExpression();
20             
21             //1.get Scheduler instance
22             SchedulerFactory schedFact = new org.quartz.impl.StdSchedulerFactory();
23             Scheduler sched = schedFact.getScheduler();
24 
25             //2.define the job and tie it to our HelloJob class
26             JobDetail job = newJob(HttSpeedUploadJob.class).withIdentity(
27                     "HttSpeedUploadJob", "HttSpeedUploadJobGroup").build();
28 
29             //3.Trigger the job to run now
30             Trigger trigger = newTrigger()
31                     .withIdentity("HttSpeedUploadJobTrigger", "HttSpeedUploadJobTriggerGroup")
32                     .startNow()
33                     .withSchedule(cronSchedule(cronExpression))
34                     .forJob(job)
35                     .build();
36             //4.Tell quartz to schedule the job using our trigger
37             sched.scheduleJob(job, trigger);
38             
39             //5.start the sched
40             sched.start();
41             logger.info("上传调度程序运行......");
42         } catch (Exception e) {
43             e.printStackTrace();
44             logger.info("上传主程序运行异常......");
45         }
46     }
47 
48 }

 

posted on 2015-03-17 17:03  qinyubin  阅读(189)  评论(0编辑  收藏  举报