2016-10-21 5 views
1

스프링 응용 프로그램 용 lib를 만들려고합니다. 그것은 예정된 작업을 가지고 있으며, 대부분 자동으로 Maven 종속성을 포함하고 있습니다.작업이 완료되지 않은 경우 스프링 스케줄러가 실행되지 않음

나는 기본적으로 다른 웹 응용 프로그램에 요청을 넘치게하는 webapp가 있습니다 (기본로드 테스트 및 실패 감지). 리퀘 스터 구현은 완전 비동기식입니다 (수동으로 구성된 비동기 실행기도 있음). 웹 앱에도 주기적으로 작업이 있지만 2 분 안에는 작업이 안정적으로 완료되지 않습니다. 아직도 괜찮아. 그러나.

두 번째 설명 된 서버에서 처음으로 설명한 lib를 사용하기 시작했을 때 lib는 신뢰할 수 없음을 나타냅니다. 더 이상 2 분마다 트리거되지 않습니다. 나는 이유를 알기에 충분한 봄 지식이 없습니다.

가장 좋은 방법은 서버 플러드 방법이 많은 비동기 작업을 시작하고 스케줄러가 이러한 작업을 시작하며 이러한 요청이 동일한 메시지 대기열로 전송된다는 것입니다.

예약 된 작업을 다른 서버의 예약 된 작업과 분리하여 2 분마다 실행되도록하는 방법이 있습니까?

+0

작업 실행 및 스케줄러 관련 구성을 구성한 방법에 대한 코드를 공유해주십시오. 도움이 될 경우이 도움말을 참조하십시오. http://stackoverflow.com/a/21409068/3838328 – Kamal

+0

지금은 코드에서 멀리 떨어져 있지만 springboot 앱입니다. 내 lib 디렉토리에서 분리 된 Executor를 정의 할 수 있다면 충분할 것이라고 생각합니다. 나는 [이] (http://stackoverflow.com/questions/32207023/multiple-threadpooltaskexecuters-spring-java-config) 내 문제를 해결할 것입니다,하지만 난 모르겠지만 지금 당장 그것을 시도 할 수 없다, 어쩌면 내일 :) – tg44

답변

0

내 연구가 흥미 롭습니다. 비동기 실행 프로그램을 구성하는 것만으로도 스케줄러가이를 사용하게됩니다. 그러나 schedulerConfigurer도 구현하면 예약 된 작업 전용으로 다른 스레드 풀이 생성됩니다.

내 구현은 2 개의 threadpool을 별도로 구현 한 것과 같습니다.

@SpringBootApplication 
@EnableAsync 
@EnableScheduling 
@ComponentScan 
public class WebService extends AsyncConfigurerSupport implements SchedulingConfigurer { 
public static void main(String[] args) { 
    System.setProperty("http.proxyHost", "localhost"); 
    System.setProperty("http.proxyPort", "8888"); 
    System.setProperty("spring.config.name", "web-server"); 
    SpringApplication.run(WebService.class, args); 
} 
@Override 
public Executor getAsyncExecutor() { 
    ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); 
    executor.setCorePoolSize(2); 
    executor.setMaxPoolSize(4); 
    executor.setQueueCapacity(500); 
    executor.setThreadNamePrefix("tester-"); 
    executor.initialize(); 
    return executor; 
} 
@Bean(destroyMethod = "shutdown", name = "scheduledExecutor") 
public Executor taskExecutor() { 
    return Executors.newScheduledThreadPool(100); 
} 

@Autowired 
@Qualifier(value="scheduledExecutor") 
Executor scheduledExecutor; 

@Override 
public void configureTasks(ScheduledTaskRegistrar taskRegistrar) { 
    taskRegistrar.setScheduler(scheduledExecutor); 
} 

내 lib 용으로 분리 된 스레드 풀을 만들 수 있을지 아직 명확하지 않지만 지금은 충분합니다.

관련 문제