我正在使用Spring Boot,并有一个异步方法。为了执行异步操作,我有以下配置,问题是如果这5个线程由于某些原因挂起,那么它将锁定应用程序,没有新任务将被执行(它只会继续接受)。我们如何为这些工作线程设置超时时间,比如120秒,以便在此之后超时并执行新任务。(是的,我正在使用固定线程池和无界队列来接受任务)
@EnableAsync
@Configuration
public class AsyncConfiguration implements AsyncConfigurer {
@Override
public Executor getAsyncExecutor() {
ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor();
taskExecutor.setCorePoolSize(5);
taskExecutor.setMaxPoolSize(5);
taskExecutor.initialize();
return taskExecutor;
}
@Override
public AsyncUncaughtExceptionHandler getAsyncUncaughtExceptionHandler() {
return new SimpleAsyncUncaughtExceptionHandler();
}
}
taskExecutor.setKeepAliveSeconds(120)
- Merve Sahin