horwat 01/03/16 13:34:09 Modified: jasper/src/share/org/apache/jasper/util SimplePool.java Log: Patch SimplePool race condition when tomcat is under load Bugzilla #747 & #728 Submitted by: [EMAIL PROTECTED] Revision Changes Path 1.2 +22 -24 jakarta-tomcat-4.0/jasper/src/share/org/apache/jasper/util/SimplePool.java Index: SimplePool.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-4.0/jasper/src/share/org/apache/jasper/util/SimplePool.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- SimplePool.java 2000/08/12 00:52:15 1.1 +++ SimplePool.java 2001/03/16 21:34:07 1.2 @@ -1,7 +1,7 @@ /* - * $Header: /home/cvs/jakarta-tomcat-4.0/jasper/src/share/org/apache/jasper/util/SimplePool.java,v 1.1 2000/08/12 00:52:15 pierred Exp $ - * $Revision: 1.1 $ - * $Date: 2000/08/12 00:52:15 $ + * $Header: /home/cvs/jakarta-tomcat-4.0/jasper/src/share/org/apache/jasper/util/SimplePool.java,v 1.2 2001/03/16 21:34:07 horwat Exp $ + * $Revision: 1.2 $ + * $Date: 2001/03/16 21:34:07 $ * * ==================================================================== * @@ -63,11 +63,6 @@ package org.apache.jasper.util; -import java.util.zip.*; -import java.net.*; -import java.util.*; -import java.io.*; - /** * Simple object pool. Based on ThreadPool and few other classes * @@ -83,12 +78,16 @@ private Object pool[]; private int max; - private int minSpare; - private int maxSpare; - private int current=-1; Object lock; + public static final int DEFAULT_SIZE=16; + + public SimplePool() { + this.max=DEFAULT_SIZE; + pool=new Object[max]; + lock=new Object(); + } public SimplePool(int max) { this.max=max; @@ -103,33 +102,32 @@ * Add the object to the pool, silent nothing if the pool is full */ public void put(Object o) { - int idx=-1; synchronized( lock ) { - if( current < max ) - idx=++current; + if( current < (max-1) ) { + current += 1; + pool[current] = o; + } } - if( idx > 0 ) - pool[idx]=o; } /** * Get an object from the pool, null if the pool is empty. */ public Object get() { - int idx=-1; + Object item = null; synchronized( lock ) { - if( current >= 0 ) - idx=current--; + if( current >= 0 ) { + item = pool[current]; + current -= 1; + } } - if( idx >= 0 ) - return pool[idx]; - return null; + return item; } - /** Return the size of the pool + /** + * Return the size of the pool */ public int getMax() { return max; } - }