billbarker    2003/09/10 21:05:02

  Modified:    util/java/org/apache/tomcat/util/threads ThreadPool.java
  Log:
  Fix potential problem with dying threads when the pool is empty.
  
  Functionally, this isn't that much different from what Remy posted on Bug #21763.  
However (at least on high-end machines) it should be able to respond faster to a 
released CM.  Since the case that all threads are dead may be able to be handled, be 
less aggressive on checking this case.
  
  Also adding debug statements, since I'm not convinced that this is the fix for 21763 
(so I'm going to do some more testing before I close the bug).
  
  Revision  Changes    Path
  1.14      +31 -23    
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.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- ThreadPool.java   7 Sep 2003 13:25:26 -0000       1.13
  +++ ThreadPool.java   11 Sep 2003 04:05:02 -0000      1.14
  @@ -308,14 +308,14 @@
       private ControlRunnable findControlRunnable() {
           ControlRunnable c=null;
   
  -        if (0 == currentThreadCount || stopThePool) {
  +        if ( stopThePool ) {
               throw new IllegalStateException();
           }
   
           // Obtain a free thread from the pool.
           synchronized(this) {
   
  -            if (currentThreadsBusy == currentThreadCount) {
  +            while (currentThreadsBusy == currentThreadCount) {
                    // All threads are busy
                   if (currentThreadCount < maxThreads) {
                       // Not all threads were open,
  @@ -323,29 +323,34 @@
                       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.
               int pos = currentThreadCount - currentThreadsBusy - 1;
               c = pool[pos];
  @@ -363,8 +368,11 @@
                       "increase maxThreads or check the servlet" +
                       " status" + currentThreadCount + " " +
                       maxThreads  );
  -         logfull=false;
  -     } 
  +            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