本帖最后由 唐志海 于 2013-11-21 20:38 编辑  
 
帮忙看下线程t1也结束了,可为什么没有输出发生异常- class stop implements Runnable
 
 - {
 
 -         private boolean flag=true;
 
 -         public synchronized void run() {
 
 -                 while(flag)
 
 -                 {
 
 -                         try{
 
 -                                 wait();
 
 -                                 
 
 -                         }
 
 -                         catch(InterruptedException e){
 
 -                                 System.out.println(Thread.currentThread().getName()+"发生异常.....");
 
 -                                 flag=false;
 
 -                         }
 
 -         
 
 -                 }
 
 -                  
 
 -         }
 
 -         
 
 -         
 
 - }
 
  
- public class StopThread
 
 - {
 
 -         public static void main(String[] args) throws InterruptedException 
 
 -         {
 
 -                 //new Thread(new stop()).start();
 
 -                 //new Thread(new stop()).start();
 
 -                 stop s=new stop();
 
 -                 Thread t=new Thread(s);
 
 -                 Thread t1=new Thread(s);
 
 -                 t.start();
 
  
-                 t1.start();
 
 -                 
 
 -                 
 
 -                 for(int i=0;i<100;i++)
 
 -                         {
 
 -                                 t.interrupt();
 
 -                                 t1.interrupt();
 
 -                                 System.out.println(i);
 
 -                         }
 
 -                 System.out.println("oooo");
 
 -         }
 
 - }
 
  复制代码 |   
        
 
    
    
    
     
 
 |