Spring AsyncRestTemplate connection pool and thread pool settings

2.7k Views Asked by At

I want to use AsyncRestTemplate for making a REST call in my service. According to Spring documentation, this class has 5 constructors( refer http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/web/client/AsyncRestTemplate.html)

AsyncRestTemplate(AsyncClientHttpRequestFactory asyncRequestFactory)-Using this AsyncClientHttpRequestFactory argument I will be able to configure the connection pool.

AsyncRestTemplate(AsyncListenableTaskExecutor taskExecutor)-Using this I will be able to configure the thread pool for the async operation.

I want to know if there is a way I could configure both connection pool and thread pool in AsyncRestTemplate.

Thank you very much in adance.

1

There are 1 best solutions below

2
On

You can set task executor in SimpleClientHttpRequestFactory also:

    ThreadPoolTaskScheduler taskExecutor = new ThreadPoolTaskScheduler();
    taskExecutor.setPoolSize(10);
    SimpleClientHttpRequestFactory simpleClientHttpRequestFactory = new SimpleClientHttpRequestFactory();
    simpleClientHttpRequestFactory.setTaskExecutor(taskExecutor);
    new AsyncRestTemplate(simpleClientHttpRequestFactory);