import java.util.HashMap;
import java.util.HashSet;
import java.util.Stack;
+import java.util.concurrent.atomic.AtomicInteger;
import javax.management.ListenerNotFoundException;
import javax.management.MBeanNotificationInfo;
* 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);
/**
*/
public int getCountAllocated() {
- return (this.countAllocated);
+ return (this.countAllocated.get());
}
// condition with unload. Bug 43683, test case #3
if (!singleThreadModel) {
newInstance = true;
- countAllocated++;
+ countAllocated.incrementAndGet();
}
} catch (ServletException e) {
throw e;
// For new instances, count will have been incremented at the
// time of creation
if (!newInstance) {
- countAllocated++;
+ countAllocated.incrementAndGet();
}
return (instance);
}
synchronized (instancePool) {
- while (countAllocated >= nInstances) {
+ while (countAllocated.get() >= nInstances) {
// Allocate a new instance if possible, or else wait
if (nInstances < maxInstances) {
try {
}
if (log.isTraceEnabled())
log.trace(" Returning allocated STM instance");
- countAllocated++;
+ countAllocated.incrementAndGet();
return (Servlet) instancePool.pop();
}
// 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();
}
// 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)));
+ countAllocated.toString()));
}
try {
Thread.sleep(delay);