Repository: incubator-gobblin Updated Branches: refs/heads/master 55b1facdc -> 291b40bf9
[GOBBLIN-504] Fix multithreading issue when HiveMetastoreClientPool is initialized Closes #2374 from yukuai518/find Project: http://git-wip-us.apache.org/repos/asf/incubator-gobblin/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-gobblin/commit/291b40bf Tree: http://git-wip-us.apache.org/repos/asf/incubator-gobblin/tree/291b40bf Diff: http://git-wip-us.apache.org/repos/asf/incubator-gobblin/diff/291b40bf Branch: refs/heads/master Commit: 291b40bf91bcb36a50fbbe29aa0e7f2740dd25f5 Parents: 55b1fac Author: Kuai Yu <[email protected]> Authored: Thu May 24 16:49:40 2018 -0700 Committer: Hung Tran <[email protected]> Committed: Thu May 24 16:49:40 2018 -0700 ---------------------------------------------------------------------- .../org/apache/gobblin/hive/HiveMetastoreClientPool.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-gobblin/blob/291b40bf/gobblin-hive-registration/src/main/java/org/apache/gobblin/hive/HiveMetastoreClientPool.java ---------------------------------------------------------------------- diff --git a/gobblin-hive-registration/src/main/java/org/apache/gobblin/hive/HiveMetastoreClientPool.java b/gobblin-hive-registration/src/main/java/org/apache/gobblin/hive/HiveMetastoreClientPool.java index 38bf9dc..6721399 100644 --- a/gobblin-hive-registration/src/main/java/org/apache/gobblin/hive/HiveMetastoreClientPool.java +++ b/gobblin-hive-registration/src/main/java/org/apache/gobblin/hive/HiveMetastoreClientPool.java @@ -59,7 +59,7 @@ public class HiveMetastoreClientPool { public static final String POOL_CACHE_TTL_MINUTES_KEY = "hive.metaStorePoolCache.ttl"; - public static Cache<Optional<String>, HiveMetastoreClientPool> poolCache = null; + private static Cache<Optional<String>, HiveMetastoreClientPool> poolCache = null; private static final Cache<Optional<String>, HiveMetastoreClientPool> createPoolCache(final Properties properties) { long duration = properties.containsKey(POOL_CACHE_TTL_MINUTES_KEY) @@ -88,8 +88,10 @@ public class HiveMetastoreClientPool { */ public static HiveMetastoreClientPool get(final Properties properties, final Optional<String> metastoreURI) throws IOException { - if (poolCache == null) { - poolCache = createPoolCache(properties); + synchronized (HiveMetastoreClientPool.class) { + if (poolCache == null) { + poolCache = createPoolCache(properties); + } } try { return poolCache.get(metastoreURI, new Callable<HiveMetastoreClientPool>() {
