public R<String> tgFx(){
long b = System.currentTimeMillis();
// 多线程开始 分析指标
ThreadPoolExecutor executor = new ThreadPoolExecutor(8, 10, 200, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<>(2));
Callable tk1 =()->{
long l = System.currentTimeMillis();
String res = tgBasicInfoService.addTgBasicInfoAll();
long l1 = System.currentTimeMillis() - l;
System.out.println("<<<====线程【1】执行完成 耗时"+ l1+ " 毫秒" );
return 1;
};
Callable tk2 =()->{
long l = System.currentTimeMillis();
tgBasicInfoService.queryPoUserRap();
long l1 = System.currentTimeMillis() - l;
System.out.println("<<<====线程【2】执行完成 耗时"+ l1+ " 毫秒" );
return 1;
};
Callable tk3 =()->{
long l = System.currentTimeMillis();
tgBasicInfoService.queryAllTg96Load();
long l1 = System.currentTimeMillis() - l;
System.out.println("<<<====线程【3】执行完成 耗时"+ l1+ " 毫秒" );
return 2;
};
Callable tk4 =()->{
long l = System.currentTimeMillis();
tgBasicInfoService.insertExpansionTg();
long l1 = System.currentTimeMillis() - l;
System.out.println("<<<====线程【4】执行完成 耗时"+ l1+ " 毫秒" );
return 2;
};
List tasks = new ArrayList<>();
tasks.add(tk1);
tasks.add(tk2);
tasks.add(tk3);
tasks.add(tk4);
long l2 = System.currentTimeMillis();
long d = l2 - b;
try {
executor.invokeAll(tasks);
return R.data("++++++++++++++++计算完成+++++++++++++++耗时==>"+CalculateUtils.div(String.valueOf(d),"1000",2)+"秒");
} catch (InterruptedException e) {
e.printStackTrace();
return R.data(e.getMessage());
}finally {
executor.shutdown();
}
}
Java线程池 同步执行多个任务
最新推荐文章于 2024-09-12 22:16:26 发布