1. 클래스 작성

package com.jw.customized.sync;


import org.apache.commons.logging.Log;

import org.apache.commons.logging.LogFactory;

import org.quartz.JobExecutionContext;

import org.quartz.JobExecutionException;

import org.quartz.StatefulJob;

import org.springframework.scheduling.quartz.QuartzJobBean;


import com.jw.customized.migration.DeptMigration;


public class SyncJob extends QuartzJobBean implements StatefulJob {

private static final Log logger = LogFactory.getLog(SyncJob.class);

private DeptMigration deptMigration = null;

public DeptMigration getDeptMigration() {

return deptMigration;

}


public void setDeptMigration(DeptMigration deptMigration) {

this.deptMigration = deptMigration;

}


@Override

protected void executeInternal(JobExecutionContext jobexecutioncontext)

       throws JobExecutionException {

if (this.deptMigration != null) {

if (this.deptMigration.isDoingExecute()) {

logger.warn("실행중입니다.");

} else {

this.deptMigration.execute();

}

}

}

}



2. xml에 설정하고 Quartz 설정

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd">

<beans default-init-method="initialize">


.....

.....


        <bean id="migration.DeptMigration" class="com.jw.customized.migration.DeptMigration">

                <property name="dbConnectionManager"><ref bean="datasource.DBConnectionManager" /></property>

        </bean>

    <!-- scheduler -->
        <bean name="SchedulerFactoryBean" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
                <property name="triggers">
                        <list>
                                <ref bean="sync.DeptMigrationJob.trigger" />
                        </list>
                </property>
                <property name="configLocation"><value>classpath:quartz.properties</value></property>
        </bean>
        <bean name="sync.DeptMigrationJob" class="org.springframework.scheduling.quartz.JobDetailBean">
                <property name="jobClass" value="com.jw.customized.sync.SyncJob" />
                <property name="jobDataAsMap">
                        <map>
                                <entry key="deptMigration"><ref bean="migration.DeptMigration" /></entry>
                        </map>
                </property>
        </bean>
        <bean id="sync.DeptMigrationJob.trigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
<!--
  SimpleTriggerBean : 몇분마다 실행....
      __ property로 repeatInterval 을 갖음
  CronTriggerBean : 정기적 실행( 매시 언제..이런식)
      __ property로 cronExpression을 갖음
-->
                <!-- see the example of method invoking job above -->
                <property name="jobDetail" ref="sync.DeptMigrationJob" />
                <!-- 매일 02:20, 12/20 분에 수행  -->
                <property name="cronExpression" value="0 20 2,12 * * ?" />
        </bean>
</beans>


'업무 > Java' 카테고리의 다른 글

[java] 시스템정보 알아내기  (0) 2012.06.22
[java] 파일에서 읽어 맵에저장  (0) 2012.06.11
[java] euc-kr , utf-8 인코딩 변환  (0) 2012.04.30
[java] hashtable 사용  (0) 2012.02.08
[java] 파일 읽기  (0) 2012.02.08

+ Recent posts