You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by re...@apache.org on 2005/09/12 12:33:12 UTC
cvs commit: jakarta-tomcat-catalina/catalina/src/share/org/apache/naming/resources ResourceCache.java
remm 2005/09/12 03:33:12
Modified: catalina/src/share/org/apache/naming/resources
ResourceCache.java
Log:
- 36594: Fix a number of issues in the class, most importantly fix updating the
cache size after a failed allocation.
- Submitted by Anil Gangolli.
Revision Changes Path
1.4 +17 -9 jakarta-tomcat-catalina/catalina/src/share/org/apache/naming/resources/ResourceCache.java
Index: ResourceCache.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat-catalina/catalina/src/share/org/apache/naming/resources/ResourceCache.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- ResourceCache.java 27 Feb 2004 14:58:54 -0000 1.3
+++ ResourceCache.java 12 Sep 2005 10:33:12 -0000 1.4
@@ -17,6 +17,8 @@
package org.apache.naming.resources;
import java.util.HashMap;
+import java.util.Random;
+
/**
* Implements a special purpose cache.
@@ -35,8 +37,14 @@
// ----------------------------------------------------- Instance Variables
-
-
+
+
+ /**
+ * Random generator used to determine elements to free.
+ */
+ protected Random random = new Random();
+
+
/**
* Cache.
* Path -> Cache entry.
@@ -227,11 +235,9 @@
// Randomly select an entry in the array
int entryPos = -1;
boolean unique = false;
- int count = 0;
while (!unique) {
unique = true;
- entryPos = (int) Math.floor(Math.random()
- * (cache.length - 1));
+ entryPos = random.nextInt(cache.length) ;
// Guarantee uniqueness
for (int i = 0; i < entriesFound; i++) {
if (toRemove[i] == entryPos) {
@@ -305,11 +311,14 @@
public void load(CacheEntry entry) {
if (entry.exists) {
- insertCache(entry);
+ if (insertCache(entry)) {
+ cacheSize += entry.size;
+ }
} else {
+ int sizeIncrement = (notFoundCache.get(entry.name) == null) ? 1 : 0;
notFoundCache.put(entry.name, entry);
+ cacheSize += sizeIncrement;
}
- cacheSize += entry.size;
}
@@ -408,5 +417,4 @@
return null;
}
-
}
---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-dev-help@jakarta.apache.org