结束线程的问题,高手指教啊,马上给分!
小弟弄线程时遇到一个麻烦:以下是源程序:
public class CountTest implements Runnable {
int count= 1, number;
public CountTest(int num)
{
number = num;
System.out.println("Create thread " + number);
}
public void run()
{
while(true)
{
System.out.println("thread " + number + ":count " + count);
System.err.println(Thread.currentThread().toString());
//if(++count== 6)
//return; 如果注释掉这两句,怎样结束这个死循环
}
}
//起六个线程
public static void main(String args[])
{
for(int i = 0; i < 6; i++)
new Thread(new CountTest(i+1)).start();
}
}
如果注释掉
//if(++count== 6)
//return; 如果注释掉这两句,怎样结束这个死循环
这两句,我想达到结束这个死循环的效果,请问怎么实现?
高手指教!