billbarker    2003/09/10 21:15:42

  Modified:    util/java/org/apache/tomcat/util/threads Tag: coyote_10
                        ThreadPool.java
  Log:
  port patch
  
  Revision  Changes    Path
  No                   revision
  No                   revision
  1.9.2.2   +34 -24    
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.9.2.1
  retrieving revision 1.9.2.2
  diff -u -r1.9.2.1 -r1.9.2.2
  --- ThreadPool.java   25 Jan 2003 04:49:24 -0000      1.9.2.1
  +++ ThreadPool.java   11 Sep 2003 04:15:42 -0000      1.9.2.2
  @@ -276,7 +276,7 @@
               throw new NullPointerException();
           }
   
  -        if(0 == currentThreadCount || stopThePool) {
  +        if( stopThePool ) {
               throw new IllegalStateException();
           }
   
  @@ -284,39 +284,46 @@
   
           // Obtain a free thread from the pool.
           synchronized(this) {
  -            if(currentThreadsBusy == currentThreadCount) {
  +            while (currentThreadsBusy == currentThreadCount) {
                    // All threads are busy
  -                if(currentThreadCount < maxThreads) {
  +                if (currentThreadCount < maxThreads) {
                       // Not all threads were open,
                       // Open new threads up to the max number of idel threads
                       int toOpen = currentThreadCount + minSpareThreads;
                       openThreads(toOpen);
                   } else {
  -                 logFull(log, currentThreadCount, maxThreads);
  +                    logFull(log, currentThreadCount, maxThreads);
                       // Wait for a thread to become idel.
  -                    while(currentThreadsBusy == currentThreadCount) {
  -                        try {
  -                            this.wait();
  -                        }
  -                     // was just catch Throwable -- but no other
  -                     // exceptions can be thrown by wait, right?
  -                     // So we catch and ignore this one, since
  -                     // it'll never actually happen, since nowhere
  -                     // do we say pool.interrupt().
  -                     catch(InterruptedException e) {
  -                         log.error("Unexpected exception", e);
  -                        }
  -
  -                        // Pool was stopped. Get away of the pool.
  -                        if(0 == currentThreadCount || stopThePool) {
  -                            throw new IllegalStateException();
  -                        }
  +                    try {
  +                        this.wait();
  +                    }
  +                    // was just catch Throwable -- but no other
  +                    // exceptions can be thrown by wait, right?
  +                    // So we catch and ignore this one, since
  +                    // it'll never actually happen, since nowhere
  +                    // do we say pool.interrupt().
  +                    catch(InterruptedException e) {
  +                        log.error("Unexpected exception", e);
  +                    }
  +                 if( log.isDebugEnabled() ) {
  +                     log.debug("Finished waiting: CTC="+currentThreadCount +
  +                               ", CTB=" + currentThreadsBusy);
  +                    }
  +                    // Pool was stopped. Get away of the pool.
  +                    if( stopThePool) {
  +                        break;
                       }
                   }
               }
  -
  +            // Pool was stopped. Get away of the pool.
  +            if(0 == currentThreadCount || stopThePool) {
  +                throw new IllegalStateException();
  +            }
  +                    
               // If we are here it means that there is a free thread. Take it.
  -            c = pool[currentThreadCount - currentThreadsBusy - 1];
  +            int pos = currentThreadCount - currentThreadsBusy - 1;
  +            c = pool[pos];
  +            pool[pos] = null;
               currentThreadsBusy++;
           }
           c.runIt(r);
  @@ -330,7 +337,10 @@
                       " status" + currentThreadCount + " " +
                       maxThreads  );
            logfull=false;
  -     } 
  +     }  else if( log.isDebugEnabled() ) {
  +            log.debug("All threads are busy " + currentThreadCount + " " +
  +                      maxThreads );
  +        }
       }
   
       /**
  
  
  

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

Reply via email to