本帖最后由 马胜平 于 2012-2-19 17:39 编辑
public class A {// 主线程启动了thread1线程,thread1启动了thread2线程
public static void main(String[]args){
new Thread(new Thread1()).start();
}
}
class Thread1 implements Runnable{
Thread t=new Thread(new Thread2());
@Override
public void run() {
t.start();
for(int i=0;i<=100;i++){
System.out.println("thread1 is running..");
}
}
class Thread2 implements Runnable{
@Override
public void run() {
for(int i=0;i<=100;i++){
System.out.println("thread2 is running..");
}
}
}
} |