当前位置:网站首页>线程池代码与测试
线程池代码与测试
2022-07-20 03:39:00 【学习微站】
@Slf4j
@SpringBootTest(classes = ReportApplication.class)
@RunWith(SpringRunner.class)
public class NewTest {
//
// private static ExecutorService executor = new ThreadPoolExecutor(10, 30,
// 60L, TimeUnit.SECONDS, new ArrayBlockingQueue(10));
private ScheduledExecutorService executor = Executors.newScheduledThreadPool(2);
@Test
public void test2() {
//执行具体业务
List<Long> idList = new LinkedList<>();
for (int i = 0; i < 10; i++) {
idList.add(Long.valueOf(i));
}
for (Long i : idList) {
System.out.println(i);
try {
//执行业务模拟===========
executor.execute(new Runnable() {
@Override
public void run() {
System.out.println("name:" + Thread.currentThread().getName());
System.out.println("thredId:" + Thread.currentThread().getId());
Date start = new Date();
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
log.error("e:", e);
}
Date end = new Date();
log.info("start:{},end:{}", start, end);
System.out.println("start:" + start + " end:" + end);
}
});
} catch (Exception e) {
log.error("threadPool e:", e);
}
}
}
}
result
0
1
2
3
4
5
6
7
8
9
name:pool-1-thread-1
thredId:111
name:pool-1-thread-2
thredId:112
边栏推荐
- leetcode 剑指 Offer 32 - I. 从上到下打印二叉树
- scala Breaks.break()、Breaks.breakable()、控制抽象
- Search insertion position of C language force deduction question 35. Classical Dichotomy
- ChromeOptions常用配置与WebUI实操
- Activiti7 workflow and Alibaba components, second office OA, information management, ERP, etc
- int类型转为double
- Clé
- [special for training courses] Introduction to tee components
- 【upload靶场1-11】基础关卡:特点、分析、利用
- C语言文件管理函数及原理
猜你喜欢
【已解决】org.apache.catalina.LifecycleException: 无法启动组件[StandardEngine[Catalina].StandardHost[localhost]
leetcode 剑指 Offer 26. 树的子结构
【upload靶场1-11】基础关卡:特点、分析、利用
Custom MVC add query
regular expression
ECS和云数据库管理
DTOS帝拓思的3D引擎将取代游戏引擎巨兽,实现国产化替代
Use regular expressions to bypass
Responsive dream weaving template lock cylinder website
连接无限·协同无界|融云首届全球企业通信云大会 WECC 来了
随机推荐
V4L2学习笔记
What do 1U, 2U and 4U of the server mean?
MySQL index
使用Dos命令生成目录文件树
JASMINER X4 became popular overseas and was praised by many well-known bloggers
Merge and sort targeted questions
[upload range 12-16] cut, picture horse
Video 25-7 Chapter 2 VGg 26 Nin 27 goolenet
Pyhon crawls Beijing's 10-year weather data
重新定义分析 - EventBridge 实时事件分析平台发布
【培训课程专用】Trustzone--配置中断的安全属性
新特性解读 | MySQL 8.0 对 GTID 的限制解除
[leetcode] sword finger offer 52 The first common node of two linked lists
利用正则表达式绕过
Leetcode sword finger offer 26 Substructure of tree
MySQL metabase & Account Management & Engine
C语言力扣第35题之搜索插入位置。经典二分法
【无标题】
Mysql -分区列(横向分区 纵向分区)
Leetcode sword finger offer 11 Rotate the minimum number of the array