基膜和糯米胶的区别:请java高手帮我注释或者解释一下这个例子?

来源:百度文库 编辑:查人人中国名人网 时间:2024/04/30 02:47:45
这是线程组的一个例子看不懂,谢谢帮助;
public class Grp implements Runnable{
public void run(){
for(;;){
System.out.println("thread: " + Thread.currentThread().getName());
try{
Thread.sleep(300);
}catch(InterruptedException e){}
}
}

public static void main(String[] args){
ThreadGroup g = new ThreadGroup("My Group");
Runnable r = new Grp();

Thread t = new Thread(g,r);
t.start();
t = new Thread(g,r);
t.start();
for(;;){
try{
Thread.sleep(5000);
}catch(InterruptedException e){}
g.suspend();
System.out.println("thread " + Thread.currentThread().getName());
try{
Thread.sleep(5000);
}catch(InterruptedException e){}
g.resume();
}
}
}