remm        2002/11/27 12:12:17

  Modified:    util/java/org/apache/tomcat/util/threads ThreadPool.java
  Log:
  - Replace the Vector with an array. The code is equivalent (or at least it
    should be).
  - If this is Not Good (TM), -1 and revert ;-)
  - I have questions on the TP and related code. Would it be possible to
    consider refactoring it, or is it a bad idea ?
  
  Revision  Changes    Path
  1.4       +13 -16    
jakarta-tomcat-connectors/util/java/org/apache/tomcat/util/threads/ThreadPool.java
  
  Index: ThreadPool.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-connectors/util/java/org/apache/tomcat/util/threads/ThreadPool.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- ThreadPool.java   2 Jul 2002 19:57:49 -0000       1.3
  +++ ThreadPool.java   27 Nov 2002 20:12:17 -0000      1.4
  @@ -87,7 +87,7 @@
       /*
        * Where the threads are held.
        */
  -    protected Vector pool;
  +    protected ControlRunnable[] pool = null;
   
       /*
        * A monitor thread that monitors the pool for idel threads.
  @@ -151,6 +151,8 @@
   
           adjustLimits();
   
  +        pool = new ControlRunnable[maxThreads];
  +
           openThreads(minSpareThreads);
           monitor = new MonitorRunnable(this);
       }
  @@ -247,8 +249,7 @@
               }
   
               // If we are here it means that there is a free thred. Take it.
  -            c = (ControlRunnable)pool.lastElement();
  -            pool.removeElement(c);
  +            c = pool[currentThreadCount - currentThreadsBusy - 1];
               currentThreadsBusy++;
           }
           c.runIt(r);
  @@ -273,9 +274,9 @@
               stopThePool = true;
               monitor.terminate();
               monitor = null;
  -            for(int i = 0 ; i < (currentThreadCount - currentThreadsBusy) ; i++) {
  +            for(int i = 0 ; i < (currentThreadCount - currentThreadsBusy - 1) ; 
i++) {
                   try {
  -                    ((ControlRunnable)(pool.elementAt(i))).terminate();
  +                    pool[i].terminate();
                   } catch(Throwable t) {
                       /*
                     * Do nothing... The show must go on, we are shutting
  @@ -304,9 +305,9 @@
                            maxSpareThreads;
   
               for(int i = 0 ; i < toFree ; i++) {
  -                ControlRunnable c = (ControlRunnable)pool.firstElement();
  -                pool.removeElement(c);
  +                ControlRunnable c = pool[currentThreadCount - currentThreadsBusy - 
1];
                   c.terminate();
  +                pool[currentThreadCount - currentThreadsBusy - 1] = null;
                   currentThreadCount --;
               }
           }
  @@ -324,7 +325,7 @@
           }
   
           currentThreadsBusy--;
  -        pool.addElement(c);
  +        pool[currentThreadCount - currentThreadsBusy - 1] = c;
           notify();
       }
   
  @@ -382,12 +383,8 @@
               toOpen = maxThreads;
           }
   
  -        if(0 == currentThreadCount) {
  -            pool = new Vector(toOpen);
  -        }
  -
           for(int i = currentThreadCount ; i < toOpen ; i++) {
  -            pool.addElement(new ControlRunnable(this));
  +            pool[i - currentThreadsBusy] = new ControlRunnable(this);
           }
   
           currentThreadCount = toOpen;
  
  
  

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to