当前位置:网站首页>多线程实现循环
多线程实现循环
2022-07-27 15:54:00 【@淡 定】
public void main( List<String> list) {
List<String> a=new ArrayList<>();
//自定义线程池
ExecutorService pool=new ThreadPoolExecutor(5,10,
1L, TimeUnit.SECONDS,
new LinkedBlockingQueue<>(3),
Executors.defaultThreadFactory(),
new ThreadPoolExecutor.AbortPolicy());
final CountDownLatch endGate = new CountDownLatch(list.size());
for (int i = 0; i < list.size(); i++) {
String str = list.get(i);
Runnable run = new Runnable() {
@Override
public void run() {
try {
Thread.sleep(1000);
//具体操作
} catch (Exception e) {
e.printStackTrace();
}finally {
endGate.countDown();
}
}
};
pool.execute(run);
//pool.submit(run);
}
try {
endGate.await();
} catch (InterruptedException e) {
e.printStackTrace();
}
pool.shutdown();
System.out.println("结束!");
return a;
}
边栏推荐
- Evaluation index of machine learning (II) -- classification evaluation index
- How to develop an online Excel spreadsheet system (Part 1)
- 用slmgr命令激活正版Win7旗舰版系统
- [user article] examples of P4 consolidation practice guide disassemble resolve
- 笔试缺考者入围教师招聘面试?河南祥符:个别考生成绩统计错误
- 【cf】#681 A. Kids Seating (Div. 2, based on VK Cup 2019-2020 - Final)
- JSP custom tag (bottom)
- Compilation and testing of raspberry pie driver code
- 树莓派驱动代码的编译和测试
- wallys/DR882-Qualcomm-Atheros-QCA9882-2T2R-MIMO-802.11ac-Mini-PCIe-Wi-Fi-Module-5G-high-power.
猜你喜欢
How to improve the security of Android applications?

初识多态

知物由学 | 从0到1搭建实时反外挂机制,多维度补充手游攻防力

面试常见问题一二

Establishing SSL connection without server‘s identity verification is not recommended

What should we pay attention to when choosing the LED display screen of the stadium

likeshop外卖点餐系统「100%开源无加密」

The Ministry of industry and information technology re governs data security, and Netease Yidun "privacy compliance" keeps the bottom line of enterprise operation

Evaluation index of machine learning (II) -- classification evaluation index

Operation of simulated examination platform for 2022 low voltage electrician examination questions
随机推荐
@Scheduled 和Quartz
[MCU] 2.2 pin function of AT89S52
机器学习——概念理解之IoU
Mysql database defines cursor in trigger
kubernetes 1.24高可用集群二进制部署
Learn from what you know | Yidun self-developed text real-time clustering technology, and wipe out the same kind of harmful content in social networks
微信小程序 实现拨打电话
C语言怎么学?这篇文章给你完整答案
【单片机】2.2 AT89S52的引脚功能
卷积神经网络——YOLOV2(YOLO9000)论文翻译
With the right tools, CI achieves twice the result with half the effort
Big gap? Requirements and conditions for candidates with different academic qualifications to take the postgraduate entrance examination
【Codeforces】 A. Computer Game
Could not obtain transaction-synchronized Session for current thread
树莓派驱动代码的编译和测试
Numpy array matrix operation
【数据库系统概论(王珊)】第4章——数据库安全性
Convolutional neural network -- Translation of yolov2 (yolo9000) papers
wallys/DR882-Qualcomm-Atheros-QCA9882-2T2R-MIMO-802.11ac-Mini-PCIe-Wi-Fi-Module-5G-high-power.
mysql解决唯一索引重复导致的插入失败问题