control.java

来自「一个TSP问题的图形演示程序」· Java 代码 · 共 53 行

JAVA
53
字号
/* *  This code is from the book: * *    Winder, R and Roberts, G (2000) Developing Java *    Software, second edition, John Wiley & Sons. * *  It is copyright (c) 2000 Russel Winder and Graham Roberts. */package SimFrameWork ;/** *  This class provides a basic extension of class Thread, providing a *  control loop and a safe way of terminating the thread. * *  @version 2.0 March 1999 *  @author Graham Roberts */public abstract class Control extends Thread {  /**   * Default constructor is declared for completeness but doesn't   * do anything   */  public Control() {  }  /**   *  Default run policy is to loop while the thread is kept active,   *  and defer all other behaviour to an abstract update method.   */  public void run() {    active = true ;    while (active) {      update() ;    }  }  /**   *  Stop the thread by setting the active flag to false.   */  public void stopControl() {    active = false ;  }  /**   *  Do whatever the thread does.   */  public abstract void update() ;  /**   *  Flag used to store active state of simulation thread.   *  Declared as volatile as its value can be changed by a thread   *  other than the simulation thread, and we want to guarantee that   *  the simulation thread always reads its current value.   */  private volatile boolean active = false ;} 

⌨️ 快捷键说明

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