Can wait (), notify () implemented; CountDownLatch may also be used to achieve the starting gun.
CountDownLatch achieve relatively simple, as follows:
package constxiong.interview; import java.util.concurrent.CountDownLatch; /** * Test to start multiple threads * @author ConstXiong */ public class TestCountDownLatch { private static CountDownLatch cld = new CountDownLatch(10); public static void main(String[] args) { for (int i = 0; i <10; i++) { Thread t = new Thread(new Runnable() { public void run() { try { . CLD the await (); // thread blocking Here, all threads waiting for completion of calls start () method, performed together } the catch (InterruptedException E) { e.printStackTrace (); } System.out.println(Thread.currentThread().getName() + ":" + System.currentTimeMillis()); } }); t.start(); cld.countDown(); } } }
- Java self-study guide
- Java interview questions summary PC client browser [Click here]
- Java mapping knowledge
- Java applets interview questions summary view, sweep the two-dimensional code