⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 controlledthread.java

📁 JAVA面向对象编程_孙卫琴yaunma
💻 JAVA
字号:
package control;
public class ControlledThread extends Thread {
  public static final int SUSP=1;
  public static final int STOP=2;
  public static final int RUN=0;

  private int state = RUN;

  public synchronized void setState( int state){
    this.state = state;
    if (state == RUN)
     notify();
  }

  public synchronized boolean checkState() {
    while(state == SUSP){
      try{
        System.out.println(Thread.currentThread().getName()+":wait");
        wait();
      }catch (InterruptedException e){throw new RuntimeException(e.getMessage()); }
    }
    if (state == STOP){
      return false;
    }
    return true;
  }
}



/****************************************************
 * 作者:孙卫琴                                     *
 * 来源:<<Java面向对象编程>>                       *
 * 技术支持网址:www.javathinker.org                *
 ***************************************************/

 


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -