While using the embedded tomcat for deploying my spring boot app, I set the async timeout as follows:
@Bean
public EmbeddedServletContainerFactory servletContainer() {
TomcatEmbeddedServletContainerFactory factory = new TomcatEmbeddedServletContainerFactory();
factory.addConnectorCustomizers(new TomcatConnectorCustomizer() {
@Override
public void customize(Connector connector) {
connector.setAsyncTimeout(60000);
}
});
return factory;
}
But,how to achieve the same when deploying to an external server, for example, websphere?
Tried using the property:
spring.mvc.async.request-timeout=600000
But this did not have any effect.
Edit:
I had tried implementing AsyncConfigurer as per Andrei's suggestion. But it did not work as expected. Below is my configuration class:
@SpringBootApplication
@EnableAsync
public class Application implements AsyncConfigurer {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
@Override
public Executor getAsyncExecutor() {
Executor executor = new ThreadPoolExecutor(10, 20, 60, TimeUnit.SECONDS, new ArrayBlockingQueue<>(10),
new ThreadPoolExecutor.AbortPolicy());
return executor;
}
@Override
public AsyncUncaughtExceptionHandler getAsyncUncaughtExceptionHandler() {
// TODO Auto-generated method stub
return new SimpleAsyncUncaughtExceptionHandler();
}
}
I have given timeout as 60 seconds, but when trying this configuration, the request was timing out after 30 seconds. Was using RestClient.
Is there something I am missing?
In the SpringApplication (implement first the interface called AsyncConfigurer
) class I would create my custom AsyncExeuctor like this:
@Override
public Executor getAsyncExecutor() {
Executor executor = new ThreadPoolExecutor(
poolSize,
maxSize,
keepAlive,
TimeUnit.SECONDS, // <--- TIMEOUT IN SECONDS
new ArrayBlockingQueue<>(qSize),
new ThreadPoolExecutor.AbortPolicy() // <-- It will abort if timeout exceeds
);
return executor;
}
You can configure the poolSize
, maxSize
, etc. in the application.properties file and then "inject" them using the @Value annotation.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.