当前位置:网站首页>Four ways to create thread pools
Four ways to create thread pools
2022-07-28 14:09:00 【Learning MicroStation】
newCachedThreadPool
Create a cacheable thread pool , Create... As needed , There used to be reusing them
newFixedThreadPool
Create a fixed thread pool , reusable
newScheduledThredPool
Create a thread pool , Arrange plan execution ( regular )
public static void main(String[] args) {
ScheduledExecutorService scheduledThreadPool = Executors.newScheduledThreadPool(3);
scheduledThreadPool.schedule(new Runnable() {
@Override
public void run() {
System.out.println(" etc. 3 second ");
}
}, 3, TimeUnit.SECONDS);
scheduledThreadPool.scheduleAtFixedRate(new Runnable() {
@Override
public void run() {
System.out.println(" Execute every three seconds after a delay of one second ");
}
}, 1, 3, TimeUnit.SECONDS);
scheduledThreadPool.scheduleAtFixedRate(() -> {
System.out.println("===============");
}, 1, 3, TimeUnit.SECONDS);
}
result
Execute every three seconds after a delay of one second
===============
etc. 3 second
Execute every three seconds after a delay of one second
===============
Execute every three seconds after a delay of one second
===============
Execute every three seconds after a delay of one second
===============
Execute every three seconds after a delay of one second
===============
newSingleThreadExecutor
Single instance execution , This thread pool has only one thread , This thread can restart a thread after the thread exception to continue to execute instead of the original thread
边栏推荐
- 每日一题——奖学金
- [lvgl events] Application of events on different components (I)
- R语言因子数据的表格和列联表(交叉表)生成:使用summay函数分析列表查看卡方检验结果判断两个因子变量是否独立(使用卡方检验验证独立性)
- Websocket chat
- DXF读写:标注样式组码中文说明
- 一文读懂如何部署具有外部数据库的高可用 K3s
- strcmp、strstr、memcpy、memmove的实现
- Poj3268 shortest path solution
- 如何有效进行回顾会议(上)?
- Entering the world of audio and video -- flv video packaging format
猜你喜欢

【服务器数据恢复】HP StorageWorks系列服务器RAID5两块盘离线的数据恢复

安全保障基于软件全生命周期-PSP应用

在 Kubernetes 中部署应用交付服务(第 1 部分)

The strongest distributed locking tool: redisson

Security assurance is based on software life cycle - networkpolicy application

Product Manager: job responsibility table

Algorithm --- different paths (kotlin)

Security assurance is based on software life cycle -istio authorization mechanism

解决uniapp微信小程序canvas不能引入字体的问题

论文研读--Masked Generative Distillation
随机推荐
每日一题——奖学金
你真的了解esModule吗
多级缓存方案
7. Dependency injection
.net for subtraction, intersection and union of complex type sets
解决uniapp微信小程序canvas不能引入字体的问题
A label_ File download (download attribute)
Custom Configuration Sections
The strongest distributed locking tool: redisson
Security assurance is based on software life cycle -istio authentication mechanism
安全保障基于软件全生命周期-PSP应用
什么是自旋锁 自旋锁是指当一个线程尝试获取某个锁时,如果该锁已被其他线程占用,就一直循环检测锁是否被释放,而不是进入线程挂起或睡眠状态。 /** * 为什么用自旋锁:多个线程对同一个变量
R language uses LM function to build multiple linear regression model, writes regression equation according to model coefficient, and uses conflict function to give 95% confidence interval of regressi
Several solutions to spanning
Tutorial on the principle and application of database system (058) -- MySQL exercise (2): single choice question
【Util】redis工具类:把redis的value序列化器修改为GenericJackson2JsonRedisSerializer,就支持返回值为对象或集合了
关于栈的理解以及实际应用场景
Understanding of stack and practical application scenarios
【LVGL事件(Events)】事件代码
Tutorial on the principle and application of database system (061) -- MySQL exercise: operation questions 21-31 (V)