From d521b7a30721e1dc1753f432ebd1cfde93a29658 Mon Sep 17 00:00:00 2001 From: "Ma,Gang" Date: Wed, 11 May 2016 15:26:19 +0800 Subject: [PATCH] Fix bug KYLIN-1676:High CPU in TrieDictionary due to incorrect use of HashMap --- .../src/main/java/org/apache/kylin/dict/TrieDictionary.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/core-dictionary/src/main/java/org/apache/kylin/dict/TrieDictionary.java b/core-dictionary/src/main/java/org/apache/kylin/dict/TrieDictionary.java index 3a05d0a..233d18e 100644 --- a/core-dictionary/src/main/java/org/apache/kylin/dict/TrieDictionary.java +++ b/core-dictionary/src/main/java/org/apache/kylin/dict/TrieDictionary.java @@ -29,7 +29,9 @@ import java.io.*; import java.lang.ref.SoftReference; import java.util.Arrays; import java.util.HashMap; +import java.util.Map; import java.util.UUID; +import java.util.concurrent.ConcurrentHashMap; /** * A dictionary based on Trie data structure that maps enumerations of byte[] to @@ -73,7 +75,7 @@ public class TrieDictionary extends Dictionary { transient private int firstByteOffset; transient private boolean enableValueCache = true; - transient private SoftReference valueToIdCache; + transient private SoftReference valueToIdCache; transient private SoftReference idToValueCache; transient private boolean enableIdToValueBytesCache = false; @@ -117,7 +119,7 @@ public class TrieDictionary extends Dictionary { } if (enableValueCache) { - valueToIdCache = new SoftReference(new HashMap()); + valueToIdCache = new SoftReference(new ConcurrentHashMap()); idToValueCache = new SoftReference(new Object[nValues]); } } @@ -145,7 +147,7 @@ public class TrieDictionary extends Dictionary { @Override final protected int getIdFromValueImpl(T value, int roundingFlag) { if (enableValueCache && roundingFlag == 0) { - HashMap cache = valueToIdCache.get(); // SoftReference to skip cache gracefully when short of memory + Map cache = valueToIdCache.get(); // SoftReference to skip cache gracefully when short of memory if (cache != null) { Integer id = null; id = (Integer) cache.get(value); -- 2.6.4