Search in sources :

Example 46 with StdSchedulerFactory

use of org.quartz.impl.StdSchedulerFactory in project java-example by 1479005017.

the class QuartzTest method testModify.

@Test
public void testModify() throws Exception {
    SchedulerFactory schedulerFactory = new StdSchedulerFactory();
    Scheduler scheduler = schedulerFactory.getScheduler();
    QuartzManager quartzManager = new QuartzManager(scheduler);
    quartzManager.addJob("myJob", "test", MyJob.class, Collections.singletonMap("x", "1"), "0/5 * * * * ?");
    quartzManager.startScheduler();
    Thread.sleep(1500);
    for (int i = 0; Thread.activeCount() > 0; i++) {
        if (i % 3 == 0) {
            quartzManager.modifyJob("myJob", "test", Collections.singletonMap("x", i + ""));
        }
        Thread.sleep(1000);
    }
}
Also used : StdSchedulerFactory(org.quartz.impl.StdSchedulerFactory) Scheduler(org.quartz.Scheduler) QuartzManager(com.example.quartz.QuartzManager) SchedulerFactory(org.quartz.SchedulerFactory) StdSchedulerFactory(org.quartz.impl.StdSchedulerFactory) Test(org.junit.Test)

Example 47 with StdSchedulerFactory

use of org.quartz.impl.StdSchedulerFactory in project jforum2 by rafaelsteil.

the class SummaryScheduler method startJob.

/**
 * Starts the summary Job. Conditions to start: Is not started yet and is enabled on the file
 * SystemGlobasl.properties. The to enable it is "summary.enabled"
 * (ConfigKeys.SUMMARY_IS_ENABLED).
 *
 * @throws SchedulerException
 * @throws IOException
 */
public static void startJob() throws SchedulerException {
    boolean isEnabled = SystemGlobals.getBoolValue(ConfigKeys.SUMMARY_IS_ENABLED);
    if (!isStarted && isEnabled) {
        String filename = SystemGlobals.getValue(ConfigKeys.QUARTZ_CONFIG);
        String cronExpression = SystemGlobals.getValue("org.quartz.context.summary.cron.expression");
        scheduler = new StdSchedulerFactory(filename).getScheduler();
        Trigger trigger = null;
        try {
            trigger = new CronTrigger(SummaryJob.class.getName(), "summaryJob", cronExpression);
            logger.info("Starting quartz summary expression " + cronExpression);
            scheduler.scheduleJob(new JobDetail(SummaryJob.class.getName(), "summaryJob", SummaryJob.class), trigger);
            scheduler.start();
        } catch (ParseException e) {
            e.printStackTrace();
        }
    }
    isStarted = true;
}
Also used : StdSchedulerFactory(org.quartz.impl.StdSchedulerFactory) CronTrigger(org.quartz.CronTrigger) JobDetail(org.quartz.JobDetail) Trigger(org.quartz.Trigger) CronTrigger(org.quartz.CronTrigger) ParseException(java.text.ParseException)

Example 48 with StdSchedulerFactory

use of org.quartz.impl.StdSchedulerFactory in project opencast by opencast.

the class CaptureNowProlongingService method activate.

/**
 * Activates the component
 *
 * @param cc
 *          the component's context
 */
public void activate(ComponentContext cc) {
    componentContext = cc;
    try {
        quartz = new StdSchedulerFactory().getScheduler();
        quartz.start();
        // create and set the job. To actually run it call schedule(..)
        final JobDetail job = new JobDetail(JOB_NAME, JOB_GROUP, Runner.class);
        job.setDurability(true);
        job.setVolatility(true);
        job.getJobDataMap().put(JOB_PARAM_PARENT, this);
        quartz.addJob(job, true);
    } catch (org.quartz.SchedulerException e) {
        throw new RuntimeException(e);
    }
}
Also used : StdSchedulerFactory(org.quartz.impl.StdSchedulerFactory) JobDetail(org.quartz.JobDetail)

Example 49 with StdSchedulerFactory

use of org.quartz.impl.StdSchedulerFactory in project yyl_example by Relucent.

the class QuartzExample method main.

public static void main(String[] args) throws Exception {
    // JobDetail job = new JobDetail();
    // job.setName("jobName");
    // job.setJobClass(HelloJob.class);
    JobDetail job = // 
    JobBuilder.newJob(HelloJob.class).withIdentity("jobName", // 
    "groupName").build();
    // CronTrigger trigger = new CronTrigger();
    // trigger.setName("triggerName");
    // trigger.setCronExpression("0/5 * * * * ?");
    Trigger trigger = // 
    TriggerBuilder.newTrigger().withIdentity("triggerName", // 
    "group").withSchedule(// 
    CronScheduleBuilder.cronSchedule("0/5 * * * * ?")).build();
    // 
    StdSchedulerFactory stdSchedulerFactory = new StdSchedulerFactory();
    // 默认从quartz.properties文件读取配置
    // stdSchedulerFactory.initialize();
    // 使用Properties设置配置信息
    Properties props = new Properties();
    props.put("org.quartz.scheduler.instanceName", "MyScheduler");
    props.put("org.quartz.threadPool.threadCount", "3");
    props.put("org.quartz.jobStore.class", "org.quartz.simpl.RAMJobStore");
    stdSchedulerFactory.initialize(props);
    Scheduler scheduler = stdSchedulerFactory.getScheduler();
    scheduler.start();
    scheduler.scheduleJob(job, trigger);
    // 运行30秒关闭
    Thread.sleep(30 * 1000);
    scheduler.shutdown();
}
Also used : StdSchedulerFactory(org.quartz.impl.StdSchedulerFactory) JobDetail(org.quartz.JobDetail) Trigger(org.quartz.Trigger) Scheduler(org.quartz.Scheduler) Properties(java.util.Properties)

Example 50 with StdSchedulerFactory

use of org.quartz.impl.StdSchedulerFactory in project gocd by gocd.

the class BackupSchedulerTest method setup.

@BeforeEach
void setup() throws SchedulerException {
    stdSchedulerFactory = new StdSchedulerFactory();
    scheduler = stdSchedulerFactory.getScheduler();
    backupScheduler = new BackupScheduler(scheduler, goConfigService, serverHealthService, backupService);
}
Also used : StdSchedulerFactory(org.quartz.impl.StdSchedulerFactory) BeforeEach(org.junit.jupiter.api.BeforeEach)

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