Java Spring TaskExecutor not starting immediately after calling taskExecutor.execute() method

Viewed 1586

I am facing an issue while using TaskExecutor in a application running on AWS Worker environment. I am using a thread pool of core size 15. TaskExecutor task is a REST webservice call which usually took 1 to 3 seconds. If the number of transactions are less, the task inside the taskExecutor is starting quickly. But if the number of of transactions are more (less than 15), the starting of the task is taking 200 milliseconds or more.

Could you please help to get any ideas to figure out the delay in task Execution start.(basically I am trying to start the rest service call execution as early as possible)

@Bean
public TaskExecutor taskExecutor() {
    ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
    executor.setCorePoolSize(15);
    executor.setMaxPoolSize(20);
    executor.initialize();
    return executor;
}


taskExecutor.execute(() -> {

        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_JSON);
        HttpEntity<String> httpEntity = new HttpEntity<String>(jsonString, headers);
        String result = restTemplate.postForObject("URL", httpEntity , 

String.class);
}});
0 Answers
Related