Quartz - 배치 실행

Programming/Java 2014.01.28 14:45 Posted by 파란크리스마스

출처 : Chapter 19. Quartz 혹은 Timer 를 사용한 스케쥴링     

DongHoReportBatch.java

package com.blueX.batch;

import java.text.SimpleDateFormat;
import java.util.Date;

import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.scheduling.quartz.QuartzJobBean;

public class DongHoReportBatch extends QuartzJobBean {

	@Override
	protected void executeInternal(JobExecutionContext jobExecutionContext) throws JobExecutionException {
		Date dt = new Date();
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd, hh:mm:ss a"); 
		System.out.println(sdf.format(dt).toString()); 
	}
	
	public static void main(String[] args) throws Exception {
		String[] configLocation = new String[] { "file:WebContent/WEB-INF/blueX-servlet.xml" };
		ApplicationContext context = new ClassPathXmlApplicationContext(configLocation);
	}

}

blueX-servlet.xml

	<bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean" autowire="no">
		<property name="triggers">
       		<list>
	         	<ref bean="dongHoReportTrigger" />
			</list>
     	</property>
     	<property name="quartzProperties">
		    <props>
		    	<prop key="org.quartz.threadPool.class">org.quartz.simpl.SimpleThreadPool</prop>
		        <prop key="org.quartz.threadPool.threadCount">5</prop>
		        <prop key="org.quartz.threadPool.threadPriority">4</prop>
		        <prop key="org.quartz.jobStore.class">org.quartz.simpl.RAMJobStore</prop>
		        <prop key="org.quartz.jobStore.misfireThreshold">60000</prop>
			</props>
		</property>
	</bean>
	
	<bean id="dongHoReportTrigger" class="org.springframework.scheduling.quartz.SimpleTriggerBean">
		<property name="jobDetail" ref="dongHoReportJob" />
		<property name="startDelay" value="60000"/> <!-- 서버 시작후 1분후 첫 실행 -->
		<property name="repeatInterval" value="300000"/> <!-- 첫 실행 후 5분 마다 실행 -->
	</bean> 
	
	<bean id="dongHoReportJob" class="org.springframework.scheduling.quartz.JobDetailBean">
		<property name="jobClass" value="com.blueX.batch.DongHoReportBatch" />
	</bean>
신고


 

티스토리 툴바