当前位置:网站首页>Creation and use of thread pool
Creation and use of thread pool
2022-07-07 05:14:00 【Yang Asang 815】
public ThreadPoolExecutor(int corePoolSize, Number of core threads
int maximumPoolSize, The maximum number of threads supported by this thread pool
long keepAliveTime, Specify the time for the thread to survive at zero
TimeUnit unit, Specify the unit of survival time second branch when God
BlockingQueue<Runnable> workQueue, Specify task queue
ThreadFactory threadFactory, Specify which thread factory to create the thread
RejectedExecutionHandler handler) The specified thread is busy When the task is full , What about the new task ?
import java.util.concurrent.*;
public class TestDamo {
public static void main(String[] args) {
/*
* public ThreadPoolExecutor(int corePoolSize, Number of core threads
int maximumPoolSize, The maximum number of threads supported by this thread pool
long keepAliveTime, Specify the time for the thread to survive at zero
TimeUnit unit, Specify the unit of survival time second branch when God
BlockingQueue<Runnable> workQueue, Specify task queue
ThreadFactory threadFactory, Specify which thread factory to create the thread
RejectedExecutionHandler handler) The specified thread is busy When the task is full , What about the new task ?
* */
ExecutorService pool=
new ThreadPoolExecutor
(3,5,8,
TimeUnit.SECONDS,new ArrayBlockingQueue<>(6),
Executors.defaultThreadFactory(),
new ThreadPoolExecutor.AbortPolicy());
MyRunable myRunable=new MyRunable();
pool.execute(myRunable);// perform Runable
/*
* Future<T>submit (Callable<T>task) perform Callable
* void shutdown() Wait for the thread to close after the task is executed
* List<Runable>shutdownNow() Close thread now , Stop the method being executed , And return the unimplemented task
* */
pool.shutdown();
}
}
class MyRunable implements Runnable{
@Override
public void run() {
try {
for (int i = 0; i < 5; i++) {
Thread.sleep(2000);
System.out.println(" Thread running :"+(i+1));
}
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}边栏推荐
- CentOS 7.9安装Oracle 21c历险记
- Array initialization of local variables
- Timer创建定时器
- 谈谈讲清楚这件事的重要性
- 【opencv】图像形态学操作-opencv标记不同连通域的位置
- 【PHP SPL笔记】
- Liste des hôtes d'inventaire dans ansible (je vous souhaite des fleurs et de la romance sans fin)
- 装饰器基础学习02
- 如何设计 API 接口,实现统一格式返回?
- Weebly mobile website editor mobile browsing New Era
猜你喜欢

Flask project uses flask socketio exception: typeerror: function() argument 1 must be code, not str

Leetcode(46)——全排列

Function pointer and pointer function in C language
[email protected]映射关系问题"/>接口间调用为什么要用json、fastjson怎么赋值的、fastjson [email protected]映射关系问题

Is PMP really useful?

Auto. JS get all app names of mobile phones

Ansible overview and module explanation (you just passed today, but yesterday came to your face)
![[opencv] image morphological operation opencv marks the positions of different connected domains](/img/c3/f437bad9432dedbbb14c8a62ba5180.png)
[opencv] image morphological operation opencv marks the positions of different connected domains

torch optimizer小解析

Liste des hôtes d'inventaire dans ansible (je vous souhaite des fleurs et de la romance sans fin)
随机推荐
U++4 接口 学习笔记
Auto.js 获取手机所有app名字
【opencv】图像形态学操作-opencv标记不同连通域的位置
Clickhouse (03) how to install and deploy Clickhouse
Comparison between thread and runnable in creating threads
Why JSON is used for calls between interfaces, how fastjson is assigned, fastjson 1.2 [email protected] Mapping relatio
10 distributed databases that take you to the galaxy
Sublime tips
谈谈讲清楚这件事的重要性
The founder has a debt of 1billion. Let's start the class. Is it about to "end the class"?
高数中值定理总结
最长不下降子序列(LIS)(动态规划)
【QT】自定义控件-Loading
ThinkPHP关联预载入with
Batch normalization (Standardization) processing
Dynamically generate tables
Talk about the importance of making it clear
STM32F103 realize IAP online upgrade application
SQL injection HTTP header injection
《二》标签