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

📄 timerservice.java

📁 RESIN 3.2 最新源码
💻 JAVA
字号:
package example;import java.util.*;import java.util.concurrent.*;import javax.webbeans.Component;import javax.webbeans.In;import com.caucho.servlet.comet.*;@Componentpublic class TimerService implements Runnable {  private ScheduledExecutorService _timer;    private Future _timerFuture;    private ArrayList<CometState> _stateList    = new ArrayList<CometState>();  public TimerService(@In ScheduledExecutorService timer)  {    _timer = timer;        _timerFuture = _timer.scheduleAtFixedRate(this, 0, 2, TimeUnit.SECONDS);  }  public void addCometState(CometState state)  {    synchronized (_stateList) {      _stateList.add(state);    }  }  /**   * The timer task wakes up every active comet state.   *   * A more sophisticated application would notify the comet states   * as part of an event-based system.   */  public void run()  {    synchronized (_stateList) {      for (int i = _stateList.size() - 1; i >= 0; i--) {        CometState state = _stateList.get(i);        if (! state.wake())          _stateList.remove(i);      }    }  }  /**   * Close the timer.   */  public void close()  {    _timerFuture.cancel(false);  }}

⌨️ 快捷键说明

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