Thread join方法的理解

public class TestJoin { static class MyRunnable implements Runnable { @Override public void run() { try { Thread.sleep(3000);// 改成synchronized (this) { this.wait(); }的话,main class也一直等待该线程,而不能结束。 } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } System.out.println("run ok!"); } } public static void main(String[] args) throws Exception { MyRunnable m = new MyRunnable(); Thread t = new Thread(m); t.join();// join() 采用 wait(0)实现,调用join()后,又交出控制权 t.start();//1.执行完毕(thread died),jvm通知,应该有一个类似notify(). System.out.println("main end!"); } }  

你可能感兴趣的:(JOIN,jvm,thread,exception,String,Class)