要完全同时(至少尽可能好)启动线程,可以使用CyclicBarrier:// We want to start just 2 threads at the same time, but let's control that // timing from the main thread. That's why we have 3 "parties" instead of 2.final CyclicBarrier gate = new CyclicBarrier(3);Thread t1 = new Thread(){ public void run(){ gate.await(); //do stuff }};Thread t2 = new Thread(){ public void run(){ gate.await(); //do stuff }};t1.start();t2.start();// At this point, t1 and t2 are blocking on the gate. // Since we gave "3" as the argument, gate is not opened yet.// Now if we block on the gate from the main thread, it will open// and all threads will start to do stuff!gate.await();System.out.println("all threads started");不必一定是CyclicBarrier,您也可以使用CountDownLatch甚至是锁。这仍然不能确保它们在标准JVM上完全同时启动,但是您可以接近它们。当进行性能测试时,保持非常接近仍然很有用。例如,如果您尝试测量具有不同数量线程的数据结构的吞吐量,则希望使用这种结构来获得最准确的结果。在其他平台上,确切地说启动线程可能是非常有效的要求。