我这个代码主线程的while循环就是执行不到,找了好久也找不出哪错了
class stopThread implements Runnable
{
private boolean flag= true;
public void run()
{
while (flag)
{
System.out.println("InterruptedException run");
}
}
public void changeFlag()
{
flag= false;
}
}
class day1208
{
public static void main(String[] args)
{
stopThread st = new stopThread();
Thread t1 = new Thread(st);
Thread t2 = new Thread(st);
t1.setDaemon(true);//守护线程
t2.setDaemon(true);
t1.start();
t2.start();
int num=0;
while (true)
{
if (num++==700)
{
//st.changeFlag();
//t1.interrupt();
//t2.interrupt();
break;
}
System.out.println(Thread.currentThread().getName()+"...."+num);
}
System.out.println("over");
}
}
|