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

搜索引擎

开发平台:

Java

  1. package net.javacoding.jspider.mockobjects;
  2. import net.javacoding.jspider.core.SpiderContext;
  3. import net.javacoding.jspider.core.task.dispatch.BaseDispatchTaskImpl;
  4. import net.javacoding.jspider.core.threading.WorkerThreadPool;
  5. /**
  6.  * Mock implementation of a dispatcher task.  It will simply dispatch a
  7.  * configured amount of Wait tasks to the pool.
  8.  *
  9.  * $Id: WaitTaskDispatcherTask.java,v 1.3 2003/03/27 17:44:32 vanrogu Exp $
  10.  *
  11.  * @author G黱ther Van Roey
  12.  */
  13. public class WaitTaskDispatcherTask extends BaseDispatchTaskImpl {
  14.     /** The thread pool we'll be dispatching tasks to. */
  15.     protected WorkerThreadPool threadPool;
  16.     /** number of tasks to dispatch. */
  17.     protected int count;
  18.     /** amount of milliseconds to wait in a task. */
  19.     protected int wait;
  20.     /**
  21.      * Public constructor.
  22.      * @param count nr of tasks to dispatch
  23.      * @param wait nr of ms to wait in these tasks
  24.      */
  25.     public WaitTaskDispatcherTask(WorkerThreadPool threadPool, SpiderContext context, int count, int wait) {
  26.         super(context);
  27.         this.threadPool = threadPool;
  28.         this.count = count;
  29.         this.wait = wait;
  30.     }
  31.     public void execute() {
  32.         for ( int i = 0; i < count; i++ ) {
  33.            threadPool.assign(new WaitTask(context, wait));
  34.         }
  35.     }
  36. }