DS's『 행복합시다 』

Carpe Programming/jsp & spring & jstl

[spring] 스케쥴러 설정

nolite 2013. 2. 18. 16:31
반응형

[servlet-context.xml]

 

<beans:import resource="schedule-context.xml"/>

 

---------------------------------------------------------------------------------------------------------------

 

task 네임스페이스 추가

 

[schedule-context.xml]

 

<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/mvc"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:beans="http://www.springframework.org/schema/beans"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:task="http://www.springframework.org/schema/task"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
        http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.0.xsd">

 

    <!-- Spring Scheduled Setting -->
    <task:scheduler id="jobScheduler" pool-size="10" />
    <task:annotation-driven scheduler="jobScheduler" />  <!-- task를 @ 어노테이션 기반으로 자동 검색 -->
    
    <beans:bean id="updateTeukBoRegionJob" class="rdems.schedule.controller.SchedulerController" />
    <beans:bean id="updateSnowWorkJob" class="rdems.schedule.controller.SchedulerController" />
    <beans:bean id="updateTyphoonTrackJob" class="rdems.schedule.controller.SchedulerController" />
    <beans:bean id="updateJHERGRMasterJob" class="rdems.schedule.controller.SchedulerController" />
    <beans:bean id="snowWorkCompleteJob" class="rdems.schedule.controller.SchedulerController" />

 

[표 참조] - http://expert0226.tistory.com/207

 

필드이름

허용 값

 초(Seconds)  0 ~ 59
 분(Minutes)  0 ~ 59

 시(Hours)

 0 ~ 23

 날(Day-of-month)

 1 ~ 31
 달(Month)  1 ~ 12 or JAN ~ DEC

 요일(Day-of-week)

 1 ~ 7 or SUN-SAT
 년도(Year) (선택가능)   빈값, 1970 ~ 2099

 

  

 

 

 

 

 

 

 

 

 

Cron 표현식의 특수문자

표현식

설명

예시

*

모든 수를 나타냄

-

값의 사이를 의미 * 10-13 * * * * 10,11,12,13분에 동작함

,

특정값 지칭 * 10,11,13 * * * * 10,11,13분에 동작함

/

값의 증가를 표현 * 0/5 * * * * 0분부터 시작해서 5분마다 동작

?

특별한 값이 없음을 나타냄(day-of-month, day-of-week 필드만 사용)

L

마지막 날을 나타냄(day-of-month, day-of-week 필드만 사용)

 

 

<!-- cron="초 분 시 일 월 요일 [년도]" -->

<task:scheduled-tasks>

        <!-- 3분 부터 10분 단위로 실행 -->
        <task:scheduled ref="updateTeukBoRegionJob" method="updateTeukBoRegion" cron="0 3,13,23,33,43,53 * * * *" />

        <!-- 10분간격으로 실행 -->
        <task:scheduled ref="updateSnowWorkJob" method="updateSnowWork" cron="0 0,10,20,30,40,50 * * * *" /> 

        <!-- 5분 부터 10분 단위로 실행 -->

        <task:scheduled ref="updateTyphoonTrackJob" method="updateTyphoonTrack" cron="0 5,15,25,35,45,55 * * * *" />

        <!-- 새벽 1시에 실행 -->
        <task:scheduled ref="updateJHERGRMasterJob" method="updateJHERGRMaster" cron="0 0 1 * * *" />
    </task:scheduled-tasks>

</beans:beans>

728x90
반응형