스프링에서 스케쥴 사용시 아래의 파일 추가
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.SchedulingConfigurer;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
import org.springframework.scheduling.config.ScheduledTaskRegistrar;
@Configuration
@EnableScheduling
public class SchedulingConfiguration implements SchedulingConfigurer {
private final int POOL_SIZE = 20;
@Override
public void configureTasks(ScheduledTaskRegistrar scheduledTaskRegistrar) {
ThreadPoolTaskScheduler threadPoolTaskScheduler = new ThreadPoolTaskScheduler();
threadPoolTaskScheduler.setPoolSize(POOL_SIZE);
threadPoolTaskScheduler.setThreadNamePrefix("batch-task-pool-");
threadPoolTaskScheduler.initialize();
scheduledTaskRegistrar.setTaskScheduler(threadPoolTaskScheduler);
}
}
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import package.path.service.impl.ClassNameServiceImpl;
@Component
public class SchdulerService{
private static final Logger LOGGER = LoggerFactory.getLogger(SchdulerService.class);
@Autowired
private ClassNameServiceImpl classNameServiceImpl;
@Scheduled(fixedDelay = 10000) //현재 작업이 끝나고 10초뒤에 실행
public void asstBtchValidate() {
this.classNameServiceImpl.method1();
}
}
'웹 개발 > JAVA' 카테고리의 다른 글
jsp에서 css,js등 임포트시 경로 관련 문제 (0) | 2015.03.13 |
---|