From 80b9e4e2ccdff9804bd44b2e0e015b31cc8fe1c5 Mon Sep 17 00:00:00 2001 From: "David E. Jones" Date: Fri, 13 Feb 2009 18:25:50 +0000 Subject: [PATCH] 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 --- .../src/org/ofbiz/base/util/cache/CacheLineTable.java | 2 +- .../base/src/org/ofbiz/base/util/cache/UtilCache.java | 2 +- .../base/src/org/ofbiz/base/util/collections/LRUMap.java | 9 +++++++++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/framework/base/src/org/ofbiz/base/util/cache/CacheLineTable.java b/framework/base/src/org/ofbiz/base/util/cache/CacheLineTable.java index c0ff40e811..894b87b68b 100644 --- a/framework/base/src/org/ofbiz/base/util/cache/CacheLineTable.java +++ b/framework/base/src/org/ofbiz/base/util/cache/CacheLineTable.java @@ -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 implements Serializable { public static final String module = CacheLineTable.class.getName(); diff --git a/framework/base/src/org/ofbiz/base/util/cache/UtilCache.java b/framework/base/src/org/ofbiz/base/util/cache/UtilCache.java index 0274cafe9d..7113884954 100644 --- a/framework/base/src/org/ofbiz/base/util/cache/UtilCache.java +++ b/framework/base/src/org/ofbiz/base/util/cache/UtilCache.java @@ -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; * * */ +@SuppressWarnings("serial") public class UtilCache implements Serializable { public static final String module = UtilCache.class.getName(); diff --git a/framework/base/src/org/ofbiz/base/util/collections/LRUMap.java b/framework/base/src/org/ofbiz/base/util/collections/LRUMap.java index 924e7ce78d..8ee404801b 100644 --- a/framework/base/src/org/ofbiz/base/util/collections/LRUMap.java +++ b/framework/base/src/org/ofbiz/base/util/collections/LRUMap.java @@ -25,6 +25,7 @@ import java.util.Map; * LifoSet - Set interface wrapper around a LinkedList * */ +@SuppressWarnings("serial") public class LRUMap extends LinkedHashMap { private int maxSize; @@ -57,4 +58,12 @@ public class LRUMap extends LinkedHashMap { 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); + } }