Configuration and use of Spring @ Async annotations

about the use of @ Async in Spring

in the course of use, it is found that @ Async annotations can be used to handle asynchronism only when < task:annotation-driven/ > is configured in applicationContext.xml.

:
<task:annotation-driven/>

:
<task:annotation-driven executor="myExecutor"/>
<task:executor id="myExecutor" pool-size="5-10" queue-capacity="200" keep-alive="180" rejection-policy="ABORT"/>

has been using the first configuration, which is handled by spring"s default thread pool. However, when querying the use of various @ Async, it is the second configuration method used. I would like to ask what are the disadvantages of using the first one, and what is the difference between the two

Jul.06,2021

the default thread pool does not necessarily meet your business needs


your question can be turned into a question of why to change the default Executor, which is also a matter of thread pool configuration.
the custom thread pool configuration is certainly more appropriate for your project, and the default thread pool configuration may result in bug.

quote Alibaba Development Manual:

[force] Thread pools are not allowed to be created using Executors, but through ThreadPoolExecutor, so

The processing method of

makes the writing students more clear about the running rules of the thread pool and avoid the risk of resource exhaustion.

description: disadvantages of each method of Executors:

1) newFixedThreadPool and newSingleThreadExecutor:

The main problem with

is that stacked request processing queues can consume a lot of memory, even OOM.

2) newCachedThreadPool and newScheduledThreadPool:

the main problem is that the maximum number of threads is that Integer.MAX_VALUE, may create a very large number of threads, or even OOM.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e91c25-1384.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e91c25-1384.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?