crontab 을 이용해서 주기적으로 쉘스크립트등을 실행했던 작업들을 spring scheduler 를 통해서 어플리케이션 안에서도 구현이 가능하다.
주기적인 데이터 백업이나 메일발송, 주기적인 헬스체크, 데이터 갱신 등에 활용 가능하다.
설정 방법
appicationContext.xml
< task:annotation-driven executor = "taskExecutor" scheduler = "taskScheduler" />
< task:executor id = "taskExecutor" pool-size = "1" />
< task:scheduler id = "taskScheduler" />
< context:component-scan base-package = "com.base.package" />
|
schedulerExample.java
package com.base.package.scheduler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
@Component
public class schedulerExample {
@Scheduled (fixedDelay = 3600000 )
public void doSomething() {
}
}
|