Example:

@Async
public void test() {
    log.info("test");
}
Copy the code

Spring Boot is not used

A breakpoint, the default is org. Springframework.. The core task. SimpleAsyncTaskExecutor

This play as its name, very simple, observe the source code, from the execution method: each execution will be a new thread, in the case of high concurrency will be infinite to create threads, the consequences can be imagined

protected void doExecute(Runnable task) { Thread thread = this.threadFactory ! = null ? this.threadFactory.newThread(task) : this.createThread(task); thread.start(); }Copy the code

Using the Spring Boot

org.springframework.boot.autoconfigure.task.TaskExecutionAutoConfiguration Will help you to automatically configure org. Springframework. Scheduling. Concurrent. ThreadPoolTaskExecutor (spring boot is 2)

However, the queue used by this thread pool is LinkedBlockingQueue, which is an unbounded queue, and at high concurrency, all tasks are queued, most likely running out of memory

The correct use of

According to the business situation a custom thread pool: www.cnblogs.com/duanxz/p/60…