현재 개발된 환경이 JAVA 1.5, TOMCAT 6.0 이다. 실제 사용한 라이브러리는
quartz-all-1.8.6.jar 을 사용하였다.
context 설정
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | <!-- DAO Definition: iBatis implementations, sqlMapClient setter Injection --> <bean id="truncTableDao" class="com.batch.dao.TruncTableDaoImpl"> <property name="sqlMapClient" ref="sqlMapClient"/> </bean> <!-- 간단한 절차 설명 Step1. 반복할 작업을 가진 JobTask 클래스를 스케쥴러를 통해 실행하게 해주는 QuartzService 에 대한 Bean 정의 Step2. JobDeailBean Step3. Quartz Trigger 정의 Step4. SchedulerFactoryBean 에 설정한 JobDeailBean 과 Trigger 주입 --> <!-- Step1. 주기적으로 실행될 JobTask 클래스 Bean 설정 --> <bean name="JobTask" class="com.batch.scheduler.JobTask"> <property name="dao" ref="truncTableDao"></property> </bean> <!-- Step2. JobDeailBean 설정 --> <bean name="JobProcess" class="org.springframework.scheduling.quartz.JobDetailBean"> <!-- jobClass: 실행시킬 클래스 --> <property name="jobClass" value="com.batch.service.QuartzService"></property> <property name="jobDataAsMap"> <map> <!-- 실행시킬 클래스의 DI --> <entry key="jobTask"> <ref bean="JobTask"/> </entry> </map> </property> </bean> <!-- Step3. Trigger 설정 Trigger의 종류 1. CronTriggerBean: Linux의 CronTab과 동일 2. SimpleTriggerBean: 보다 간단한 Trigger --> <bean id="cronTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean"> <property name="jobDetail" ref="JobProcess"></property> <!-- 1시간 마다 반복 --> <property name="cronExpression" value="0 0 0/1 * * ?" /> <!-- 15초 마다 반복 --> <!-- <property name="cronExpression" value="0/15 * * * * ?"/> --> <!-- value는 1000 이 1초 <property name="repeatInterval" value="10000"></property> --> </bean> <!-- Step4. SchedulerFactoryBean 에 설정한 JobDeailBean 과 Trigger 주입 --> <bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean"> <property name="jobDetails"> <list> <ref bean="JobProcess"/> </list> </property> <property name="triggers"> <list> <ref bean="cronTrigger"/> </list> </property> </bean> |
이제 모든 소스와 설정이 마무리 되었다. 서버를 실행해보면 다음과 나온다. 그럼 정상이며,
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | 14 [ContainerBackgroundProcessor[StandardEngine[Catalina]]] INFO org.quartz.impl.StdSchedulerFactory - Using default implementation for ThreadExecutor 29 [ContainerBackgroundProcessor[StandardEngine[Catalina]]] INFO org.quartz.core.SchedulerSignalerImpl - Initialized Scheduler Signaller of type: class org.quartz.core.SchedulerSignalerImpl 29 [ContainerBackgroundProcessor[StandardEngine[Catalina]]] INFO org.quartz.core.QuartzScheduler - Quartz Scheduler v.1.8.6 created. 30 [ContainerBackgroundProcessor[StandardEngine[Catalina]]] INFO org.quartz.simpl.RAMJobStore - RAMJobStore initialized. 31 [ContainerBackgroundProcessor[StandardEngine[Catalina]]] INFO org.quartz.core.QuartzScheduler - Scheduler meta-data: Quartz Scheduler (v1.8.6) 'org.springframework.scheduling.quartz.SchedulerFactoryBean#0' with instanceId 'NON_CLUSTERED' Scheduler class: 'org.quartz.core.QuartzScheduler' - running locally. NOT STARTED. Currently in standby mode. Number of jobs executed: 0 Using thread pool 'org.quartz.simpl.SimpleThreadPool' - with 10 threads. Using job-store 'org.quartz.simpl.RAMJobStore' - which does not support persistence. and is not clustered. 31 [ContainerBackgroundProcessor[StandardEngine[Catalina]]] INFO org.quartz.impl.StdSchedulerFactory - Quartz scheduler 'org.springframework.scheduling.quartz.SchedulerFactoryBean#0' initialized from an externally provided properties instance. 31 [ContainerBackgroundProcessor[StandardEngine[Catalina]]] INFO org.quartz.impl.StdSchedulerFactory - Quartz scheduler version: 1.8.6 33 [ContainerBackgroundProcessor[StandardEngine[Catalina]]] INFO org.quartz.core.QuartzScheduler - JobFactory set to: org.springframework.scheduling.quartz.AdaptableJobFactory@7c2999bb [02-21 17:31:41:583]<INFO > : Starting Quartz Scheduler now 34 [ContainerBackgroundProcessor[StandardEngine[Catalina]]] INFO org.quartz.core.QuartzScheduler - Scheduler org.springframework.scheduling.quartz.SchedulerFactoryBean#0_$_NON_CLUSTERED started. |
다음과 같이 설정해놓은 시간에 JOB이 실행되고 해당 테이블을 조회해보면 정상적으로 TRUNCATE 된 것을 확인 할 수 있다.
1 2 3 4 | 2014-02-21 17:00:00,020 DEBUG [java.sql.Connection.debug(27)] {conn-100072} Preparing Statement: TRUNCATE TABLE SESSION 2014-02-21 17:00:00,020 DEBUG [java.sql.PreparedStatement.debug(27)] {pstm-100073} Executing Statement: TRUNCATE TABLE SESSION 2014-02-21 17:00:00,021 DEBUG [java.sql.PreparedStatement.debug(27)] {pstm-100073} Parameters: [] 2014-02-21 17:00:00,021 DEBUG [java.sql.PreparedStatement.debug(27)] {pstm-100073} Types: [] |
댓글 없음:
댓글 쓰기