KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > axis2 > util > threadpool > ThreadWorker


1 package org.apache.axis2.util.threadpool;
2
3 import org.apache.commons.logging.Log;
4 import org.apache.commons.logging.LogFactory;
5
6 /**
7  * This is the thread worker for the Axis2's thread pool
8  * This will pick a worker from the thread pool and executes its
9  * <code>doWork()</code> method of the particular worker.
10  */

11 public class ThreadWorker extends Thread JavaDoc {
12     protected static Log log = LogFactory.getLog(ThreadWorker.class.getName());
13     private boolean stop;
14     private ThreadPool pool;
15
16     public void setPool(ThreadPool pool) {
17         this.pool = pool;
18     }
19
20     public boolean isStop() {
21         return stop;
22     }
23
24     public void setStop(boolean stop) {
25         this.stop = stop;
26     }
27
28     public void run() {
29         while (!stop) {
30             AxisWorker axisWorker = null;
31             try {
32                 axisWorker = pool.getWorker();
33                 if (axisWorker != null)
34                     axisWorker.doWork();
35                 sleep(ThreadPool.SLEEP_INTERVAL);
36             } catch (InterruptedException JavaDoc e) {
37                 log.error(e);
38             }
39         }
40     }
41 }
42
Popular Tags