public class TestJoin{ public static void main(String[] args){ Thread t = new Thread(new MyRunner()); t.start(); try{ t.join(); } catch(InterruptedException e){ e.printStackTrace(); } for(int i=0;i<10;i++){ System.out.println("Main:" + i); } } } class MyRunner implements Runnable{ public void run(){ for(int i=0;i<10;i++){ System.out.println("MyRunner:" + i); try{ Thread.sleep(1000); } catch(InterruptedException e){ e.printStackTrace(); } } } }
测试Thread类的join()方法
猜你喜欢
转载自www.cnblogs.com/yxfyg/p/12418531.html
今日推荐
周排行