当前位置:网站首页>What is a thread pool?
What is a thread pool?
2022-06-11 05:42:00 【Zippx.】
In object oriented programming Creating and destroying objects is time consuming Because an object is created to obtain memory resources or other resources stay java Especially in China The virtual machine keeps the view track of each object In order to be able to garbage collection after the object is destroyed Therefore, one way to improve service efficiency is to reduce the number of creation and destruction of objects as much as possible In particular, some resource objects are destroyed This is the reason why pooled resource technology comes into being
As the name suggests, thread pool is to create several executable threads in advance and put them into a pool When needed, get threads from the pool without creating them There is no need to destroy the thread after use Instead, it returns to the pool, reducing the overhead of creation and destruction
A thread pool consists of four basic components
1. Thread pool manager (ThrredPool)
Used to create and manage thread pools Including creating thread pools Destroy thread pool Add a new task
2. Worker pool (PoolWorker)
Threads in thread pool Waiting when there is no task You can cycle tasks
3. Task interface (Task)
The interface that each character must implement Implementation of tasks scheduled by worker threads It mainly specifies the entry of tasks The closing work after the implementation of the task Task execution status, etc
4. Task queue (TaskQuery)
①newSingleThreadExecutor
The thread pool of a single thread , That is, only one thread works in the thread pool at a time , Single thread serial execution task
②newFixedThreadExecutor(n)
A fixed number of thread pools , Not submitting a task is a thread , Until the maximum number of thread pools , Then it enters the waiting queue until the previous task is completed
③newCacheThreadExecutor( Recommended )
Cacheable thread pool , When the thread pool size exceeds the number of threads needed to process the task , Then it will recycle some of the idle ( It's usually 60 No execution per second ) The thread of , When a mission comes , And intelligently add new threads to execute .
④newScheduleThreadExecutor
Unlimited thread pool , Supports timed and periodic execution threads
边栏推荐
- AltiumDesigner2020导入3D Body-SOLIDWORKS三维模型
- Opencv learning path (2-1) -- Deep parsing imread function
- ReferenceError: server is not defined
- JS promise, async, await simple notes
- es-ik 安装报错
- Create cool collectionviewcell conversion animation
- 使用Genymotion Scrapy控制手机
- 使用Batch设置IP地址
- Maximum number of points on the line ----- hash table solution
- 自定义View之基础篇
猜你喜欢

Control your phone with genymotion scratch

推荐一款免费的内网穿透开源软件,可以在测试本地开发微信公众号使用

Jsonobject jsonarray for parsing

NDK learning notes (I)

String sorting times --- bubble sorting deformation

Error:Execution failed for task ':app:buildNative'. & gt; A problem occurred'x/x/x/'NDK build' error resolution

Multithreading tutorial (XXI) double checked locking problem

BERT知识蒸馏

(十五)红外通信

Deep learning distributed training
随机推荐
[元数据]LinkedIn-DataHub
Redis setup (sentinel mode)
js promise,async,await简单笔记
NDK learning notes (XI) POSIX sockect local communication
JS promise, async, await simple notes
Opencv learning path (2-3) -- Deep parsing imshow function
Cocoapods installation error
Bit operation marks multiple switches with one parameter
1.使用阿里云对象OSS(初级)
Why is the smart door lock so popular? What about the smart door locks of MI family and zhiting?
NFC Development -- difference between ID card and IC card (M1 card and CPU card) (III)
NFC Development -- utility tools and development documents (IV)
数据接入平台方案实现(游族网络)
安装Oracle数据库
ImageView supporting single finger sliding and double finger scaling
Analysis while experiment - a little optimization of memory leakage in kotlin
Combination sum Ⅳ -- leetcode exercise
ELK日志系统实战(六):技术选型之vector与filebeat对比
22、生成括号
27. Remove elements