larryi 01/02/28 11:21:23 Modified: src/share/org/apache/tomcat/util Tag: tomcat_32 SimplePool.java Log: Applied patch to race condition. Bugzilla Bug #728. Submitted by: [EMAIL PROTECTED] Similar changes were already present in MAIN branch. This patch cleaned the code up a little better. Will update the MAIN branch to match these changes. Revision Changes Path No revision No revision 1.3.2.1 +22 -24 jakarta-tomcat/src/share/org/apache/tomcat/util/Attic/SimplePool.java Index: SimplePool.java =================================================================== RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/util/Attic/SimplePool.java,v retrieving revision 1.3 retrieving revision 1.3.2.1 diff -u -r1.3 -r1.3.2.1 --- SimplePool.java 2000/05/26 17:32:17 1.3 +++ SimplePool.java 2001/02/28 19:21:22 1.3.2.1 @@ -1,7 +1,7 @@ /* - * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/util/Attic/SimplePool.java,v 1.3 2000/05/26 17:32:17 costin Exp $ - * $Revision: 1.3 $ - * $Date: 2000/05/26 17:32:17 $ + * $Header: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/util/Attic/SimplePool.java,v 1.3.2.1 2001/02/28 19:21:22 larryi Exp $ + * $Revision: 1.3.2.1 $ + * $Date: 2001/02/28 19:21:22 $ * * ==================================================================== * @@ -63,11 +63,6 @@ package org.apache.tomcat.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; } - } --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, email: [EMAIL PROTECTED]