From fad6cae019d3dbca9c143855d77f4d2b11c6df3b Mon Sep 17 00:00:00 2001 From: PJ Fanning Date: Tue, 15 Oct 2024 16:13:17 +0000 Subject: try to make ExcelAntWorkbookUtilFactory thread safe git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1921338 13f79535-47bb-0310-9956-ffa450edef68 --- .../excelant/util/ExcelAntWorkbookUtilFactory.java | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) (limited to 'poi-excelant') diff --git a/poi-excelant/src/main/java/org/apache/poi/ss/excelant/util/ExcelAntWorkbookUtilFactory.java b/poi-excelant/src/main/java/org/apache/poi/ss/excelant/util/ExcelAntWorkbookUtilFactory.java index 55c4896705..7838a5d6eb 100644 --- a/poi-excelant/src/main/java/org/apache/poi/ss/excelant/util/ExcelAntWorkbookUtilFactory.java +++ b/poi-excelant/src/main/java/org/apache/poi/ss/excelant/util/ExcelAntWorkbookUtilFactory.java @@ -27,7 +27,7 @@ import java.util.Map; */ public final class ExcelAntWorkbookUtilFactory { - private static Map workbookUtilMap; + private static final Map workbookUtilMap = new HashMap<>(); private ExcelAntWorkbookUtilFactory() { } @@ -41,16 +41,14 @@ public final class ExcelAntWorkbookUtilFactory { * a freshly instantiated one if none did exist before. */ public static ExcelAntWorkbookUtil getInstance(String fileName) { - if(workbookUtilMap == null) { - workbookUtilMap = new HashMap<>(); + synchronized (workbookUtilMap) { + if(workbookUtilMap.containsKey(fileName)) { + return workbookUtilMap.get(fileName); + } + + ExcelAntWorkbookUtil wbu = new ExcelAntWorkbookUtil(fileName); + workbookUtilMap.put(fileName, wbu); + return wbu; } - - if(workbookUtilMap.containsKey(fileName)) { - return workbookUtilMap.get(fileName); - } - - ExcelAntWorkbookUtil wbu = new ExcelAntWorkbookUtil(fileName); - workbookUtilMap.put(fileName, wbu); - return wbu; } } -- cgit v1.2.3