timer.java
来自「本人课程设计时做的一个用struts框架实现的基于cmmi2的项目管理系统的原型」· Java 代码 · 共 109 行
JAVA
109 行
/* * @(#)Timer * * Copyright (c) 1998 Karl Moss. All Rights Reserved. * * You may study, use, modify, and distribute this software for any * purpose provided that this copyright notice appears in all copies. * * This software is provided WITHOUT WARRANTY either expressed or * implied. * * @author Karl Moss * @version 1.0 * @date 11Mar98 * */package com.cmmi2pms.common.timer;/** * <p>This class implements a simple timer. Every time the * timer clock cycle that is specified expires the TimerEvent * method on the given TimerListener object will be invoked. * This gives the object a chance to perform some type of * timeout checking. */public class Timer extends Thread{ // TimerListener to receive TimerEvent notifications TimerListener m_timerListener; // Number of seconds in each timer cycle int m_cycle; boolean m_stopFlag = false; boolean m_runFlag = false; // Object to be supplied with the TimerEvent notification Object m_object; /** * <p>Constructs a new Timer object * * @param timerListener Object that will receive TimerEvent * notifications * @param cycle Number of seconds in each timer cycle */ public Timer(TimerListener timerListener, int cycle) { m_timerListener = timerListener; m_cycle = cycle; m_object = null; } /** * <p>Constructs a new Timer object * * @param timerListener Object that will receive TimerEvent * notifications * @param cycle Number of seconds in each timer cycle * @param object Object to be supplied with the TimerEvent * notification */ public Timer(TimerListener timerListener, int cycle, Object object) { m_timerListener = timerListener; m_cycle = cycle; m_object = object; } /** * <p>Runs the timer. The timer will run until stopped and * fire a TimerEvent notification every clock cycle */ public void run() { m_runFlag = true; // Loop until stopped while ( !m_stopFlag ) { try { // Sleep for the clock cycle synchronized(this){wait(m_cycle * 1000);} } catch (InterruptedException ex) { } // Fire a TimerEvent if ( !m_stopFlag&&m_timerListener != null ) { m_timerListener.TimerEvent(m_object); } } m_runFlag = false; } public boolean getStopFlag() { return m_stopFlag; } public boolean getRunFlag() { return m_runFlag; } public void end() { m_stopFlag = true; }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?