一代风华:请java高手帮我注释或者解释一下这个例子?

来源:百度文库 编辑:神马品牌网 时间:2024/04/28 23:46:00
这是线程组的一个例子看不懂,谢谢帮助;
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();
}
}
}