package com.gzhj.controller;
import cn.hutool.core.thread.ThreadUtil;
import java.util.concurrent.CountDownLatch;
public class MyThreadUtil {
public static void main(String[] args) {
int size = 10;
CountDownLatch latch = ThreadUtil.newCountDownLatch(size);
for(int i = 0 ; i < size ; i++){
ThreadUtil.execAsync(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
System.out.println("线程:" + Thread.currentThread().getName() + ",开始...");
try {
Thread.sleep(300);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("线程:" + Thread.currentThread().getName() + ",结束," + latch.getCount());
latch.countDown();
}
});
}
System.out.println("线程设置完毕");
try {
latch.await();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("业务执行完毕");
}
}
hutool类多线程的使用
最新推荐文章于 2024-04-27 17:30:34 发布