实验七 : java多线程, 线程中创建线程

实验代码请参看百度网盘

public class TestThread1 {

/**

* @param args

*/

public static void main(String[] args) {

// TODO Auto-generated method stub

for(int i=0;i<10;i++){

new Thread(new AAA1(i)).start();

}

}

}

class AAA1 implements Runnable{

int i;

AAA1(int ii){

i=ii;

}

@Override

public void run() {

System.out.println("count "+i+ " "+Thread.currentThread().getName()+" AAA1"+Thread.currentThread().getThreadGroup());

new Thread(new BBB1(i)).start();

}

}

class BBB1 implements Runnable{

int i;

BBB1(int ii){

i=ii;

}

@Override

public void run() {

try {

Thread.sleep(1000);

} catch (InterruptedException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

System.out.println("count "+i+ " "+Thread.currentThread().getName()+" BBB "+Thread.currentThread().getThreadGroup());

new Thread(new CCC1(i)).start();

}

}

class CCC1 implements Runnable{

int i;

CCC1(int ii){

i=ii;

}

@Override

public void run() {

try {

Thread.sleep(1000);

} catch (InterruptedException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

System.out.println("count "+i+ " "+Thread.currentThread().getName()+" CCC1 "+Thread.currentThread().getThreadGroup());

}

}

猜你喜欢

转载自frankytony.iteye.com/blog/2262239