From 4e6b3db99fd9a87926fd6c23e1876a6febb8985b Mon Sep 17 00:00:00 2001 From: liyafan82 Date: Fri, 3 Jul 2020 12:50:01 +0800 Subject: [PATCH] ARROW-9315: [Java] Fix the failure of testAllocationManagerType --- .../org/apache/arrow/memory/BaseAllocator.java | 2 +- .../memory/DefaultAllocationManagerOption.java | 17 +++++++++++------ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/java/memory/src/main/java/org/apache/arrow/memory/BaseAllocator.java b/java/memory/src/main/java/org/apache/arrow/memory/BaseAllocator.java index d7c225ce5c2..922a655c008 100644 --- a/java/memory/src/main/java/org/apache/arrow/memory/BaseAllocator.java +++ b/java/memory/src/main/java/org/apache/arrow/memory/BaseAllocator.java @@ -716,7 +716,7 @@ abstract static class Config { */ @Value.Default AllocationManager.Factory getAllocationManagerFactory() { - return DefaultAllocationManagerOption.DEFAULT_ALLOCATION_MANAGER_FACTORY; + return DefaultAllocationManagerOption.getDefaultAllocationManagerFactory(); } /** diff --git a/java/memory/src/main/java/org/apache/arrow/memory/DefaultAllocationManagerOption.java b/java/memory/src/main/java/org/apache/arrow/memory/DefaultAllocationManagerOption.java index a65252762e6..7f4e54f0bd1 100644 --- a/java/memory/src/main/java/org/apache/arrow/memory/DefaultAllocationManagerOption.java +++ b/java/memory/src/main/java/org/apache/arrow/memory/DefaultAllocationManagerOption.java @@ -39,8 +39,7 @@ public class DefaultAllocationManagerOption { /** * The default allocation manager factory. */ - public static final AllocationManager.Factory DEFAULT_ALLOCATION_MANAGER_FACTORY = - getDefaultAllocationManagerFactory(); + private static AllocationManager.Factory DEFAULT_ALLOCATION_MANAGER_FACTORY = null; /** * The allocation manager type. @@ -83,19 +82,25 @@ static AllocationManagerType getDefaultAllocationManagerType() { } static AllocationManager.Factory getDefaultAllocationManagerFactory() { + if (DEFAULT_ALLOCATION_MANAGER_FACTORY != null) { + return DEFAULT_ALLOCATION_MANAGER_FACTORY; + } AllocationManagerType type = getDefaultAllocationManagerType(); - switch (type) { case Netty: - return getNettyFactory(); + DEFAULT_ALLOCATION_MANAGER_FACTORY = getNettyFactory(); + break; case Unsafe: - return getUnsafeFactory(); + DEFAULT_ALLOCATION_MANAGER_FACTORY = getUnsafeFactory(); + break; case Unknown: LOGGER.info("allocation manager type not specified, using netty as the default type"); - return getFactory(CheckAllocator.check()); + DEFAULT_ALLOCATION_MANAGER_FACTORY = getFactory(CheckAllocator.check()); + break; default: throw new IllegalStateException("Unknown allocation manager type: " + type); } + return DEFAULT_ALLOCATION_MANAGER_FACTORY; } private static AllocationManager.Factory getFactory(String clazzName) {