From 954edc4ce39fb48eb91eb02f80dc84687554d272 Mon Sep 17 00:00:00 2001 From: "Ma,Gang" Date: Wed, 11 May 2016 15:17:07 +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 8aa4eb6..3660925 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 @@ -31,7 +31,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 @@ -75,7 +77,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; @@ -119,7 +121,7 @@ public class TrieDictionary extends Dictionary { } if (enableValueCache) { - valueToIdCache = new SoftReference(new HashMap()); + valueToIdCache = new SoftReference(new ConcurrentHashMap()); idToValueCache = new SoftReference(new Object[nValues]); } } @@ -147,7 +149,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