日期:2014-05-20 浏览次数:20726 次
package com.justdoit.thread; public class TestJoin { public static void main(String[] args) { MyThread2 my = new MyThread2("MyThread2"); my.start(); try { my.join(); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } for(int i=0;i<=10;i++){ System.out.println(i+Thread.currentThread().getName()); } } } class MyThread2 extends Thread{ MyThread2(String name){ super(name); } public void run(){ for(int i=0;i<=10;i++){ System.out.println(i+Thread.currentThread().getName()); try { sleep(100); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } }