测试工具启动会递归的方式进行子进程的消息获取,目前有2种常用的ExecutorService / ForkJoinPool
为了测试哪种效果较好,我们来写个测试Demo,循环5555555次+1(加锁),统计每种执行完后耗时和GC数据
结果很明显,递归线程池使用ForkJoinPool更佳
int nCpu = Runtime.getRuntime().availableProcessors();
ExecutorService executorPool = Executors.newFixedThreadPool(nCpu);
ForkJoinPool forkJoinPool = new ForkJoinPool(nCpu);
TestData:5555555 , RunTime:1543 ms :ExecutorService executorPool
TestData:5555555 , RunTime:746 ms :ForkJoinPool forkJoinPool
原文地址:https://www.cnblogs.com/weimjsam/p/10468792.html
时间: 2024-10-08 19:24:29