class C_Dxc_StopXianCheng
{
public static void main(String[] args)
{
StopThread st = new StopThread();
Thread t1 = new Thread(st);
Thread t2 = new Thread(st);
t1.start();
t2.start();
int num = 0;
while(true)
{
if(num++ == 60)
{
//st.changFlag();
t1.interrupt();
t2.interrupt();
break;
}
System.out.println(Thread.currentThread().getName() + "----" + num);
}
System.out.println("over");
}
}
class StopThread implements Runnable
{
private boolean flag = true;
public void run()
{
while(flag)
{
try
{
wait();
}
catch(InterruptedException e)
{
System.out.println(Thread.currentThread().getName() + "------Exception");
flag = false;
}
System.out.println(Thread.currentThread().getName() + "------run");
}
}
public void changFlag()
{
flag = false;
}
}
跟视频里面的代码一模一样 为什么eclipse会出现这样的错误 郁闷死了
|