Changed LRUMap.get to be synchronized to hopefully resolve issue reported by Philippe Mouawad in Jira #OFBIZ-2186; comments in code discuss why this is needed; get is ONLY synchronized for the LRUMap, and not for caches where there is no size limit
git-svn-id: https://svn.apache.org/repos/asf/ofbiz/trunk@744205 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
@@ -35,7 +35,7 @@ import org.ofbiz.base.util.ObjectType;
|
||||
import org.ofbiz.base.util.UtilValidate;
|
||||
import org.ofbiz.base.util.collections.LRUMap;
|
||||
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
public class CacheLineTable<K, V> implements Serializable {
|
||||
|
||||
public static final String module = CacheLineTable.class.getName();
|
||||
|
||||
@@ -20,7 +20,6 @@ package org.ofbiz.base.util.cache;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.MissingResourceException;
|
||||
@@ -46,6 +45,7 @@ import org.ofbiz.base.util.UtilValidate;
|
||||
* </ul>
|
||||
*
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public class UtilCache<K, V> implements Serializable {
|
||||
|
||||
public static final String module = UtilCache.class.getName();
|
||||
|
||||
@@ -25,6 +25,7 @@ import java.util.Map;
|
||||
* LifoSet - Set interface wrapper around a LinkedList
|
||||
*
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public class LRUMap<K, V> extends LinkedHashMap<K, V> {
|
||||
private int maxSize;
|
||||
|
||||
@@ -57,4 +58,12 @@ public class LRUMap<K, V> extends LinkedHashMap<K, V> {
|
||||
return size() > maxSize;
|
||||
}
|
||||
|
||||
/**
|
||||
* An override for the LinkedHashMap.get method that is synchronized to be thread safe.
|
||||
* The LinkedHashMap.get method is not synchronized, as made very clear in the JavaDocs, and since it does modify internal state and in this case needs to be usable by more than one thread at once, making it synchronized.
|
||||
*/
|
||||
@Override
|
||||
public synchronized V get(Object key) {
|
||||
return super.get(key);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user