MonitorThread.java
上传用户:qing5858
上传日期:2015-10-27
资源大小:6056k
文件大小:1k
源码类别:

搜索引擎

开发平台:

Java

  1. package net.javacoding.jspider.core.threading;
  2. import net.javacoding.jspider.api.event.monitor.MonitorEvent;
  3. import net.javacoding.jspider.core.dispatch.EventDispatcher;
  4. /**
  5.  * $Id: MonitorThread.java,v 1.3 2003/02/27 16:47:48 vanrogu Exp $
  6.  */
  7. public abstract class MonitorThread extends Thread {
  8.     protected EventDispatcher dispatcher;
  9.     protected int interval;
  10.     public MonitorThread ( EventDispatcher dispatcher, int interval, String subject ) {
  11.         super ( subject + " monitor" );
  12.         setDaemon(true);
  13.         this.dispatcher = dispatcher;
  14.         this.interval = interval;
  15.     }
  16.     public void run ( ) {
  17.         MonitorEvent event = null;
  18.         while ( true ) {
  19.             try {
  20.                 Thread.sleep(interval);
  21.             } catch (InterruptedException e) {
  22.                 Thread.currentThread().interrupt();
  23.             }
  24.             event = doMonitorTask ( );
  25.             dispatcher.dispatch(event);
  26.         }
  27.     }
  28.     public abstract MonitorEvent doMonitorTask ( );
  29. }