Index: /tc6.0.x/trunk/java/org/apache/catalina/core/StandardWrapper.java =================================================================== --- /tc6.0.x/trunk/java/org/apache/catalina/core/StandardWrapper.java (revision 566663) +++ /tc6.0.x/trunk/java/org/apache/catalina/core/StandardWrapper.java (working copy) @@ -28,6 +28,7 @@ import java.util.HashSet; import java.util.Properties; import java.util.Stack; +import java.util.concurrent.atomic.AtomicInteger; import java.security.AccessController; import java.security.PrivilegedActionException; import java.security.PrivilegedExceptionAction; @@ -135,7 +136,7 @@ * The count of allocations that are currently active (even if they * are for the same instance, as will be true on a non-STM servlet). */ - protected int countAllocated = 0; + protected AtomicInteger countAllocated = new AtomicInteger(0); /** @@ -340,7 +341,7 @@ */ public int getCountAllocated() { - return (this.countAllocated); + return (this.countAllocated.get()); } @@ -817,7 +818,7 @@ if (!singleThreadModel) { if (log.isTraceEnabled()) log.trace(" Returning non-STM instance"); - countAllocated++; + countAllocated.incrementAndGet(); return (instance); } @@ -825,7 +826,7 @@ synchronized (instancePool) { - while (countAllocated >= nInstances) { + while (countAllocated.get() >= nInstances) { // Allocate a new instance if possible, or else wait if (nInstances < maxInstances) { try { @@ -847,7 +848,7 @@ } if (log.isTraceEnabled()) log.trace(" Returning allocated STM instance"); - countAllocated++; + countAllocated.incrementAndGet(); return (Servlet) instancePool.pop(); } @@ -868,13 +869,13 @@ // If not SingleThreadModel, no action is required if (!singleThreadModel) { - countAllocated--; + countAllocated.decrementAndGet(); return; } // Unlock and free this instance synchronized (instancePool) { - countAllocated--; + countAllocated.decrementAndGet(); instancePool.push(servlet); instancePool.notify(); } @@ -1347,13 +1348,13 @@ // Loaf a while if the current instance is allocated // (possibly more than once if non-STM) - if (countAllocated > 0) { + if (countAllocated.get() > 0) { int nRetries = 0; long delay = unloadDelay / 20; - while ((nRetries < 21) && (countAllocated > 0)) { + while ((nRetries < 21) && (countAllocated.get() > 0)) { if ((nRetries % 10) == 0) { log.info(sm.getString("standardWrapper.waiting", - new Integer(countAllocated))); + new Integer(countAllocated.get()))); } try { Thread.sleep(delay);