Author: erwan
Date: Wed Mar 23 20:44:17 2011
New Revision: 1084732
URL:
http://svn.apache.org/viewvc?rev=1084732&view=revLog:
OFBIZ-4220 a patch from Philippe Mouawad: Current implementation of UtilCache has a memory leak if maxInMemory is set
Modified:
ofbiz/trunk/framework/base/src/org/ofbiz/base/util/cache/UtilCache.java
Modified: ofbiz/trunk/framework/base/src/org/ofbiz/base/util/cache/UtilCache.java
URL:
http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/org/ofbiz/base/util/cache/UtilCache.java?rev=1084732&r1=1084731&r2=1084732&view=diff==============================================================================
--- ofbiz/trunk/framework/base/src/org/ofbiz/base/util/cache/UtilCache.java (original)
+++ ofbiz/trunk/framework/base/src/org/ofbiz/base/util/cache/UtilCache.java Wed Mar 23 20:44:17 2011
@@ -49,6 +49,7 @@ import org.ofbiz.base.util.UtilObject;
import org.ofbiz.base.util.UtilValidate;
import com.googlecode.concurrentlinkedhashmap.ConcurrentLinkedHashMap;
+import com.googlecode.concurrentlinkedhashmap.EvictionListener;
import com.googlecode.concurrentlinkedhashmap.ConcurrentLinkedHashMap.Builder;
/**
@@ -63,8 +64,8 @@ import com.googlecode.concurrentlinkedha
*
*/
@SuppressWarnings("serial")
-public class UtilCache<K, V> implements Serializable {
-
+public class UtilCache<K, V> implements Serializable, EvictionListener<Object, CacheLine<V>> {
+
public static final String module = UtilCache.class.getName();
/** A static Map to keep track of all of the UtilCache instances. */
@@ -143,6 +144,7 @@ public class UtilCache<K, V> implements
} else {
memoryTable = new Builder<Object, CacheLine<V>>()
.maximumWeightedCapacity(maxMemSize)
+ .listener(this)
.build();
}
if (this.useFileSystemStore) {
@@ -1027,4 +1029,9 @@ public class UtilCache<K, V> implements
public static <K, V> UtilCache<K, V> findCache(String cacheName) {
return (UtilCache<K, V>) UtilCache.utilCacheTable.get(cacheName);
}
+
+ @Override
+ public void onEviction(Object key, CacheLine<V> value) {
+ ExecutionPool.removePulse(value);
+ }
}