当前位置:网站首页>Creation of thread pool
Creation of thread pool
2022-06-10 23:08:00 【InfoQ】
Creation of thread pool
To create a thread pool, you need to enter several parameters , as follows .
1)corePoolSize( The basic size of the thread pool ): When a task is submitted to the thread pool , The thread pool creates a thread to perform a task , Even if other idle basic threads can perform new tasks, threads will be created , When the number of tasks to be executed is larger than the basic size of the thread pool, it will not be created anymore . If the thread pool is called prestartAllCoreThreads() Method , The thread pool is created ahead of time and starts all the base threads .
2)runnableTaskQueue( Task queue ): The blocking queue used to hold tasks waiting to be executed . You can select the following blocking queues .
- ArrayBlockingQueue: It is a bounded blocking queue based on array structure , This queue is FIFO( fifo ) The principle sorts the elements .
- LinkedBlockingQueue: A blocking queue based on linked list structure , This queue is FIFO Sorting elements , Throughput is usually higher ArrayBlockingQueue. Static factory method Executors.newFixedThreadPool() Using this queue .
- SynchronousQueue: A blocked queue that does not store elements . Each insert must wait until another thread calls the remove operation , Otherwise, the insert operation is always blocked , Throughput is usually higher
- Linked-BlockingQueue, Static factory method Executors.newCachedThreadPool Using this queue .
- PriorityBlockingQueue: An infinite blocking queue with priority .
3)maximumPoolSize( Maximum number of thread pools ): The maximum number of threads allowed to be created by the thread pool . If the queue is full , And the number of threads created is less than the maximum number of threads , The thread pool creates a new thread to execute the task . It is worth noting that , If the boundless task queue parameter is used, it has no effect .
4)ThreadFactory: Factory for setting up thread creation , You can set a more meaningful name for each created thread through the thread factory . Using open source framework guava Provided ThreadFactoryBuilder You can quickly set meaningful names for threads in the thread pool , The code is as follows .
```java
new ThreadFactoryBuilder().setNameFormat("XX-task-%d").build();
- AbortPolicy: Throw an exception directly .
- CallerRunsPolicy: Only the thread where the caller is running the task .
- DiscardOldestPolicy: Discard the nearest task in the queue , And carry out the current task .
- DiscardPolicy: Don't deal with , discarded .
边栏推荐
- C automatically generates Oracle table creation statement according to excel
- C language internal skill cultivation [integer stored in memory]
- DC2 of vulnhub
- Is there any risk in opening an account with BOC securities? Is it safe?
- Storage engine analysis
- ICML2022 | 從零開始重新審視端到端的語音到文本翻譯
- 【006】初识字符串
- 视频融合云服务EasyCVR集群录像事件查询无效是什么原因?
- Opencv_ 100 questions_ Chapter II (6-10)
- Array, list, set, map, properties dependency injection format
猜你喜欢

Distributed Foundation

28岁自学编程会不会太晚了?靠谱吗?
![[tcapulusdb knowledge base] tcapulusdb tcapdb capacity expansion and contraction introduction](/img/3b/6546846fb7bbccbb0abe91422549ed.png)
[tcapulusdb knowledge base] tcapulusdb tcapdb capacity expansion and contraction introduction

数组、List、Set、Map、Properties依赖注入格式

1. Introduction to tornado & introduction to tornado project in this column

Mmdetection dataloader construction

原生支持 ARM64 的首个版本!微软 Win11/10 免费工具集 PowerToys 0.59 发布

Web3 ecological decentralized financial platform sealem Finance

Redis数据结构

Can Huawei matepad become the secondary screen of your laptop?
随机推荐
聚簇索引和非聚簇索引
Interpretation of dataset class of mmdetection
Sherri Monroe被任命为增材制造商绿色贸易协会的新任执行董事
锁机制
MySQL组合索引不被命中使用的情况
[tcapulusdb knowledge base] tcapulusdb tcapdb capacity expansion and contraction introduction
汇编:汇编与C派系语言混用以及对应LLDB常用指令
js敏感信息泄露检测工具
The definition of the metauniverse and the seven infinite features
[content co creation] issue 17: summer is hot and you are so sweet! Participating in the signing of Huawei cloud Xiaobian, there is always a pattern gift bag that moves you!
Static routing configuration of serial interface in router experiment (Supplement)
Web3 ecological decentralized financial platform sealem Finance
数据与信息资源共享平台(五)
原生支持 ARM64 的首个版本!微软 Win11/10 免费工具集 PowerToys 0.59 发布
IP anti query domain name
Icml2022 | reexamine end-to-end voice to text translation from scratch
Distributed Foundation
Template_ Calculate number of combinations
PKI/TLS瑞士军刀之cfssl
2022 t elevator repair test question simulation test question bank and online simulation test