develog

Quartz test 본문

Dev/Java

Quartz test

냐옴 2013. 12. 11. 14:32

 

package test;

import java.util.Date;
import org.quartz.JobDataMap;
import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.SimpleTrigger;
import org.quartz.impl.StdSchedulerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import test.util.JndiUtil;

public class TestQuartz {

    private static ApplicationContext context;

    public static void main(String[] args) throws Exception {
        System.out.println("START");
        System.out.println("-------------------------------------------");
        JndiUtil.init();
        context = new ClassPathXmlApplicationContext("test/config/beans.xml");
        testTestJob();
        System.out.println("-------------------------------------------");
        System.out.println("END");
    }

    public static void testTestJob() throws Exception {
        JobDataMap jobDataMap = new JobDataMap();
        jobDataMap.put("testService", context.getBean("testService"));
        testScheduler("test.util.TestJob", jobDataMap);
    }

    public static void testScheduler(String className, JobDataMap jobDataMap) throws SchedulerException, ClassNotFoundException {
        JobDetail job = new JobDetail();
        job.setName("testJob");
        job.setJobClass(Class.forName(className));
        job.setJobDataMap(jobDataMap);
        SimpleTrigger trigger = new SimpleTrigger();
        trigger.setName("testTrigger");
        trigger.setStartTime(new Date());
        trigger.setRepeatCount(0);
        trigger.setRepeatInterval(1000);
        Scheduler scheduler = new StdSchedulerFactory().getScheduler();
        scheduler.start();
        scheduler.scheduleJob(job, trigger);
    }

}

 

'Dev > Java' 카테고리의 다른 글

System.out 파일로 출력  (0) 2013.12.11
Spring 테스트 Log4j 초기화  (0) 2013.12.11
jndi test 2  (0) 2013.12.11
applicationContext.xml, sqlMapConfig, configLocation (classpath or file)  (0) 2013.12.09
@ContextConfiguration  (0) 2013.12.09
Comments