Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

What is the principle of Executor?

Shulou Source: shulou.com Published: 2022-06-02 10:41:26 10月01日 Update

This article introduces you what is the principle of Executor, the content is very detailed, interested friends can refer to, hope to be helpful to you.

1. Introduction of Executor thread pool system. 1. Introduction of Executor framework

Executor: the uppermost parent interface of the java thread pool framework. In Executor, there is only the executor () method, which means that the thread pool of type Runnable is committed and executed.

ExecutorService: a subinterface of Executor, where the submit () method receives either Runnable or Callable parameters, and closes the thread pool using the shutdown () method after use, and no longer receives new tasks.

AbstractExecutorService: the default implementation class for ExecutorService.

ScheduledExecutorService: a subinterface of ExecutorService, which can be used for scheduled task scheduling.

ScheduledThreadPoolExecutor: provides another thread pool, thread pool for deferred and periodic execution.

ThreadPoolExecutor: the core class of AbstractExecutorService thread pool, which inherits from Java. The main function of Java thread pool is to create thread pool, assign thread resources to tasks, and execute tasks.

2. ThreadPoolExecutor source code parsing

ThreadPoolExecutor has several overloaded constructors, and we analyze the role of each parameter based on the most complete constructor.

Public ThreadPoolExecutor (int corePoolSize, / / number of core thread pools int maximumPoolSize, / / maximum number of thread pools long keepAliveTime, / / the number of threads is greater than the number of core thread pools The maximum survival time of idle threads TimeUnit unit, / / the time unit of the parameter BlockingQueue workQueue, / / thread waiting queue ThreadFactory threadFactory / / set the factory RejectedExecutionHandler handler for creating threads) {/ / set the deny policy if (corePoolSize < 0 | | maximumPoolSize)

Tags: Threads tasks methods cores queues parameters interfaces maximum cycle periodicity quantity time principle advantage system content function multiple size unlimited Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple Shulou Tech Info Xiaomi MySQL macOS