What tools in spring are similar to ThreadPoolExecutor?

Alibaba cloud Q & A 2022-02-13 08:23:05 阅读数:58

tools spring similar threadpoolexecutor

Spring Which of them and ThreadPoolExecutor Similar tools ?

Take the answer 1:

 Picture matching 5.png

What I want to emphasize is SimpleAsyncTaskExecutor,Spring Used in @Async annotation , The bottom is based on SimpleAsyncTaskExecutor To carry out the task , It's just that it's not a thread pool , It's a new thread every time . In addition, I want to emphasize that Executor Interface .Java Beginners tend to take it for granted that Executor The end class is a thread pool . We can do it in JDK Of execute See this comment on the method :

/*** Executes the given command at some time in the future. The command* may execute in a new thread, in a pooled thread, or in the calling* thread, at the discretion of the {@code Executor} implementation.*/

therefore , Its job is not to provide a thread pool interface , But to provide a “ In the future, execute orders ” The interface of . What really represents the meaning of thread pool , yes ThreadPoolExecutor class , instead of Executor Interface .

source :《Java Developer interview treasure book 》, link :https://developer.aliyun.com/topic/download?id=7899

copyright:author[Alibaba cloud Q & A],Please bring the original link to reprint, thank you. https://en.javamana.com/2022/02/202202130823038119.html