多线程效率测试

// 多线程并发
public static void main(String[] args) {
    long start = System.currentTimeMillis();
    for (int i = 0; i < 10; i++) {
        new Thread(() -> {
            // 线程体
        }).start();
    }
    while (Thread.activeCount() > 2) {
        Thread.yield();
    }
    long end = System.currentTimeMillis();
    System.out.println("线程执行完毕,所需时间: " + end - start);
}
posted @ 2022-04-21 11:41  不写代码想写诗的虫子  阅读(38)  评论(0)    收藏  举报