threadtimertask.java

来自「p2p仿真器。开发者可以工作在覆盖层中进行创造和测试逻辑算法或者创建和测试新的服」· Java 代码 · 共 48 行

JAVA
48
字号
package planet.util.timer;

/**
 * This concrete implementation extends the java.util.TimerTask and adapt
 * this implementation to use the superclass. It is required to implement
 * TimerTask to use with ThreadTimer. 
 * 
 * @author <a href="mailto: jordi.pujol@estudiants.urv.es">Jordi Pujol</a>
 * Date: 07/05/2004
 * @see planet.util.timer.ThreadTimer ThreadTimer
 */
public abstract class ThreadTimerTask extends java.util.TimerTask implements TimerTask {
	private boolean finished = false;
	
	/**
	 * Initialize this TimerTask. 
	 */
	public ThreadTimerTask() {
		super();
	}

	/**
	 * Cancels this TimerTask. If this task is in execution
	 * it normally finish.
	 * @see planet.util.timer.TimerTask#cancel()
	 * @return true if it avoid almost one execution of this task.
	 */
	public boolean cancel() {
		finished = true;
		return super.cancel();
	}
	
	/**
	 * Implements this method to make the concrete necessary job. 
	 * @see planet.util.timer.TimerTask#run()
	 */
	public abstract void run();
	
	/**
	 * Inform if this TimerTask has been cancelled.
	 * @see planet.util.timer.TimerTask#isFinished()
	 * @return true if this TimerTask has been cancelled.
	 */
	public boolean isFinished() {
		return finished;
	}
}

⌨️ 快捷键说明

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