Spring boot application using the entire processor when AsyncTaskExecutor is configured

I have the following configuration in my Spring Boot application:

@Configuration @EnableAsync @Slf4j public class AsyncConfig { private static final int BUFFER = 1024; @Bean public AsyncTaskExecutor singleThreadAsyncTaskExecutor(Environment env) { RingBufferAsyncTaskExecutor rbAsyncExecutor = new RingBufferAsyncTaskExecutor(env); rbAsyncExecutor.setName("rb-executor"); rbAsyncExecutor.setBacklog(BUFFER); rbAsyncExecutor.setProducerType(ProducerType.SINGLE); rbAsyncExecutor.setWaitStrategy(new YieldingWaitStrategy()); log.info("Async task executor loaded"); return rbAsyncExecutor; } } 

when I run it, CPU usage reaches 100% (sometimes 100 pieces):

enter image description here

research using visualvm i see this

enter image description here

but when I delete the AsyncTaskExecutor instance, the CPU load goes up by 0.4% and visualvm shows me just 1% of the CPU usage.
I found this problem when deploying it with docker, I saw how my use of the host hit the ceiling.
I tried to reduce the buffer size (it was 2048) to 1024, but nothing changed.
Without this bean, my @Async services @Async not work asynchronously. ( No TaskExecutor bean found for async processing )

+5
source share
1 answer

I think I decided.
What I did was use ThreadPoolTaskExecutor instead of RingBuffer as below

 @Bean public AsyncTaskExecutor getAsync(){ ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); executor.setCorePoolSize(7); executor.setMaxPoolSize(42); executor.setQueueCapacity(11); executor.setThreadNamePrefix("AsyncExec-"); executor.initialize(); return executor; } 

for some reason, ThreadPoolTaskExecutor lighter than others.
I got this from spring framework doc

+3
source

All Articles