Update of /cvsroot/hibernate/Hibernate3/src/org/hibernate/util
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3858/src/org/hibernate/util
Modified Files:
SimpleMRUCache.java SoftLimitMRUCache.java
Log Message:
HHH-1486 : fixed concurrent access issues in the two MRU caches
Index: SimpleMRUCache.java
===================================================================
RCS file: /cvsroot/hibernate/Hibernate3/src/org/hibernate/util/SimpleMRUCache.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- SimpleMRUCache.java 9 Jan 2006 15:55:15 -0000 1.2
+++ SimpleMRUCache.java 15 Feb 2006 16:35:34 -0000 1.3
@@ -4,7 +4,6 @@
import java.io.Serializable;
import java.io.IOException;
-import java.util.Iterator;
/**
* Cache following a "Most Recently Used" (MRU) algorithm for maintaining a
@@ -36,15 +35,11 @@
return cache.get( key );
}
- public Object put(Object key, Object value) {
+ public synchronized Object put(Object key, Object value) {
return cache.put( key, value );
}
- public Iterator entries() {
- return cache.entrySet().iterator();
- }
-
- public int size() {
+ public synchronized int size() {
return cache.size();
}
@@ -56,4 +51,8 @@
in.defaultReadObject();
init();
}
+
+ public synchronized void clear() {
+ cache.clear();
+ }
}
Index: SoftLimitMRUCache.java
===================================================================
RCS file: /cvsroot/hibernate/Hibernate3/src/org/hibernate/util/SoftLimitMRUCache.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- SoftLimitMRUCache.java 9 Jan 2006 15:55:15 -0000 1.1
+++ SoftLimitMRUCache.java 15 Feb 2006 16:35:34 -0000 1.2
@@ -5,7 +5,6 @@
import java.io.Serializable;
import java.io.IOException;
-import java.util.Iterator;
/**
* Cache following a "Most Recently Used" (MRY) algorithm for maintaining a
@@ -55,27 +54,19 @@
return result;
}
- public Object put(Object key, Object value) {
+ public synchronized Object put(Object key, Object value) {
softReferenceCache.put( key, value );
return strongReferenceCache.put( key, value );
}
- public int size() {
+ public synchronized int size() {
return strongReferenceCache.size();
}
- public int softSize() {
+ public synchronized int softSize() {
return softReferenceCache.size();
}
- public Iterator entries() {
- return strongReferenceCache.entrySet().iterator();
- }
-
- public Iterator softEntries() {
- return softReferenceCache.entrySet().iterator();
- }
-
private void init() {
strongReferenceCache = new LRUMap( strongReferenceCount );
}
@@ -84,4 +75,9 @@
in.defaultReadObject();
init();
}
+
+ public synchronized void clear() {
+ strongReferenceCache.clear();
+ softReferenceCache.clear();
+ }
}
|