多线程效率测试


// 多线程并发
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);
}