상세 컨텐츠

본문 제목

[spring] spring scheduled를 이용해서 매분마다 스케줄링

헉!!/jsp, java

by 권태성 2014. 3. 7. 10:00

본문


xml 설정

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

<beans xmlns="http://www.springframework.org/schema/beans"

    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

    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.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">


    <context:component-scan base-package="test.schedule" />

    <task:annotation-driven />

</beans>



@Scheduled 어노테이션을 사용하여 스프링 스케줄링을 사용할 수 있습니다.

스케줄러에서 매 시간마다 작동하도록 지정할땐 fixedDelay를 사용하고 cron 형식으로 지정된 시간마다 작동하도록 할때는 cron을 사용해서 지정합니다.

@Scheduled(fixedDelay = 600000) //프로그램이 시작된 시점부터 10분마다 실행 됩니다.

public void testRun(){

  ....

}

@Scheduled(cron = "0 * * * * *") //매 분마다 정시에 실행됩니다.

public void testRun(){

  ....

}


cron 형식으로 사용할때는 cron = "분 시 월 요일 년도" 로 지정할 수 있습니다.








관련글 더보기