Search in sources :

Example 1 with QuartzManager

use of com.example.quartz.QuartzManager in project java-example by 1479005017.

the class QuartzTest method test.

@Test
public void test() throws Exception {
    SchedulerFactory schedulerFactory = new StdSchedulerFactory();
    Scheduler scheduler = schedulerFactory.getScheduler();
    QuartzManager quartzManager = new QuartzManager(scheduler);
    // 每1000毫秒执行一次,重复执行3次,共执行4次
    quartzManager.addJob("myJob", "test", MyJob.class, Collections.singletonMap("x", "1"), 1000L, 3);
    quartzManager.startScheduler();
    while (Thread.activeCount() > 0) Thread.yield();
}
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 2 with QuartzManager

use of com.example.quartz.QuartzManager 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)

Aggregations

QuartzManager (com.example.quartz.QuartzManager)2 Test (org.junit.Test)2 Scheduler (org.quartz.Scheduler)2 SchedulerFactory (org.quartz.SchedulerFactory)2 StdSchedulerFactory (org.quartz.impl.StdSchedulerFactory)2