java 线程

  Thread a = new Thread(){
   public void run() {
    while(isRunning ){
     // do something
     if(isInterrupted()){
      break;
     }
    }
   }
   
   boolean isRunning = true;
   
   public void close(){
    isRunning = false;
    setNotify();
   }
   
   public synchronized void setNotify(){
    notify();
   }
   
  };
  
  a.interrupt();

你可能感兴趣的:(java 线程)