📄 control.java
字号:
/* * 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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -