public class Test { public static void main(String[] args) { MyThread myThread = new MyThread("m1"); myThread.start(); //产生分支,子线程开始执行 try{ myThread.join();//------等待合并myThread子线程,主线程才开始执行 } catch(InterruptedException e) {} for(int i = 1; i <= 10; i++) { System.out.println("I am main thread"); } } } class MyThread extends Thread { MyThread(String s) {//给线程起名字的构造方法 super(s); } public void run() { for(int i = 0 ; i <= 10; i++) { System.out.println("I'm " + getName()); try { sleep(1000); } catch(InterruptedException e) { return; } } } }