Search in sources :

Example 31 with StdSchedulerFactory

use of org.quartz.impl.StdSchedulerFactory in project dq-easy-cloud by dq-open-cloud.

the class LoadExample method run.

public void run() throws Exception {
    Logger log = LoggerFactory.getLogger(LoadExample.class);
    // First we must get a reference to a scheduler
    SchedulerFactory sf = new StdSchedulerFactory();
    Scheduler sched = sf.getScheduler();
    log.info("------- Initialization Complete -----------");
    // schedule 500 jobs to run
    for (int count = 1; count <= _numberOfJobs; count++) {
        JobDetail job = // ask scheduler
        newJob(SimpleJob.class).withIdentity("job" + count, "group_1").requestRecovery().build();
        // tell the job to delay some small amount... to simulate work...
        long timeDelay = (long) (Math.random() * 2500);
        job.getJobDataMap().put(SimpleJob.DELAY_TIME, timeDelay);
        Trigger trigger = newTrigger().withIdentity("trigger_" + count, "group_1").startAt(// space fire times a small bit
        futureDate((10000 + (count * 100)), IntervalUnit.MILLISECOND)).build();
        sched.scheduleJob(job, trigger);
        if (count % 25 == 0) {
            log.info("...scheduled " + count + " jobs");
        }
    }
    log.info("------- Starting Scheduler ----------------");
    // start the schedule
    sched.start();
    log.info("------- Started Scheduler -----------------");
    log.info("------- Waiting five minutes... -----------");
    // wait five minutes to give our jobs a chance to run
    try {
        Thread.sleep(300L * 1000L);
    } catch (Exception e) {
    // 
    }
    // shut down the scheduler
    log.info("------- Shutting Down ---------------------");
    sched.shutdown(true);
    log.info("------- Shutdown Complete -----------------");
    SchedulerMetaData metaData = sched.getMetaData();
    log.info("Executed " + metaData.getNumberOfJobsExecuted() + " jobs.");
}
Also used : StdSchedulerFactory(org.quartz.impl.StdSchedulerFactory) TriggerBuilder.newTrigger(org.quartz.TriggerBuilder.newTrigger) Logger(org.slf4j.Logger) StdSchedulerFactory(org.quartz.impl.StdSchedulerFactory)

Example 32 with StdSchedulerFactory

use of org.quartz.impl.StdSchedulerFactory in project incubator-gobblin by apache.

the class SchedulerService method startUp.

@Override
protected void startUp() throws SchedulerException {
    StdSchedulerFactory schedulerFactory = new StdSchedulerFactory();
    if (this.quartzProps.isPresent() && this.quartzProps.get().size() > 0) {
        schedulerFactory.initialize(this.quartzProps.get());
    }
    this.scheduler = schedulerFactory.getScheduler();
    this.scheduler.start();
}
Also used : StdSchedulerFactory(org.quartz.impl.StdSchedulerFactory)

Example 33 with StdSchedulerFactory

use of org.quartz.impl.StdSchedulerFactory in project elastic-job by dangdangdotcom.

the class DaemonTaskScheduler method initializeScheduler.

private Scheduler initializeScheduler() throws SchedulerException {
    StdSchedulerFactory factory = new StdSchedulerFactory();
    factory.initialize(getBaseQuartzProperties());
    return factory.getScheduler();
}
Also used : StdSchedulerFactory(org.quartz.impl.StdSchedulerFactory)

Example 34 with StdSchedulerFactory

use of org.quartz.impl.StdSchedulerFactory in project elastic-job by dangdangdotcom.

the class JobScheduler method createScheduler.

private Scheduler createScheduler(final boolean isMisfire) {
    Scheduler result;
    try {
        StdSchedulerFactory factory = new StdSchedulerFactory();
        factory.initialize(getBaseQuartzProperties(isMisfire));
        result = factory.getScheduler();
        result.getListenerManager().addTriggerListener(jobExecutor.getSchedulerFacade().newJobTriggerListener());
    } catch (final SchedulerException ex) {
        throw new JobSystemException(ex);
    }
    return result;
}
Also used : StdSchedulerFactory(org.quartz.impl.StdSchedulerFactory) SchedulerException(org.quartz.SchedulerException) Scheduler(org.quartz.Scheduler) JobSystemException(com.dangdang.ddframe.job.exception.JobSystemException)

Example 35 with StdSchedulerFactory

use of org.quartz.impl.StdSchedulerFactory in project druid by alibaba.

the class QuartzTest method setUp.

@Override
protected void setUp() throws Exception {
    Properties props = new Properties();
    props.load(getClass().getClassLoader().getResourceAsStream("bvt/quartz/quartz.properties"));
    factory = new StdSchedulerFactory(props);
    scheduler = factory.getScheduler();
}
Also used : StdSchedulerFactory(org.quartz.impl.StdSchedulerFactory) Properties(java.util.Properties)

Aggregations

StdSchedulerFactory (org.quartz.impl.StdSchedulerFactory)66 SchedulerFactory (org.quartz.SchedulerFactory)29 SchedulerException (org.quartz.SchedulerException)22 Scheduler (org.quartz.Scheduler)19 JobDetail (org.quartz.JobDetail)17 Logger (org.slf4j.Logger)14 Date (java.util.Date)11 Properties (java.util.Properties)11 Trigger (org.quartz.Trigger)11 JobKey (org.quartz.JobKey)7 JobDataMap (org.quartz.JobDataMap)6 TriggerBuilder.newTrigger (org.quartz.TriggerBuilder.newTrigger)5 InputStream (java.io.InputStream)4 Test (org.junit.Test)4 DateBuilder.nextGivenSecondDate (org.quartz.DateBuilder.nextGivenSecondDate)4 SimpleTrigger (org.quartz.SimpleTrigger)4 ParseException (java.text.ParseException)3 CronTrigger (org.quartz.CronTrigger)3 SimpleThreadPool (org.quartz.simpl.SimpleThreadPool)3 QuartzManager (com.example.quartz.QuartzManager)2