shutdown和standby區別,一個是,臨時中止一個是完全中止不可恢復squarzt

瓜瓜東西發表於2014-12-18


squarzt


package com.newegg.frontservice.common.quarzt.singlequarzttest;

import java.util.Date;

import org.quartz.CronScheduleBuilder;
import org.quartz.JobBuilder;
import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.SchedulerFactory;
import org.quartz.SimpleScheduleBuilder;
import org.quartz.Trigger;
import org.quartz.TriggerBuilder;
import org.quartz.impl.StdSchedulerFactory;

/**
 * 呼叫任務的類
 * 
 * @author lhy
 * 
 */
public class SchedulerTest {
    public static void main(String[] args) {
        
        SchedulerFactory schedulerfactory = new StdSchedulerFactory();
        Scheduler scheduler = null;
        try {
            scheduler = schedulerfactory.getScheduler();
            
            JobDetail job =
                JobBuilder.newJob(MyJob.class)
                    .withIdentity("job1", "jgroup1")
                    .build();
            JobDetail job2 =
                JobBuilder.newJob(MyJob.class)
                .withIdentity("job2", "jgroup1")
                .build();
            
            Trigger trigger =
                TriggerBuilder.newTrigger()
                    .withIdentity("cornTrigger", "triggerGroup")
                    .withSchedule(CronScheduleBuilder.cronSchedule("5-10 * * * * ? *"))
                    .startNow()
                    .build();
            Trigger trigger2 =
                TriggerBuilder.newTrigger()
                .withIdentity("cornTrigger2", "triggerGroup")
                .withSchedule(CronScheduleBuilder.cronSchedule("15-17 * * * * ? *"))
                .startNow()
                .build();
            
            scheduler.scheduleJob(job, trigger);
            scheduler.scheduleJob(job2,trigger2);
            scheduler.start();
          //   scheduler.shutdown();
            scheduler.standby();
            scheduler.start();
        }
        catch (Exception e) {
            e.printStackTrace();
        }
        
    }
}


相關文章