diff options
author | PJ Fanning <fanningpj@apache.org> | 2024-10-15 16:13:17 +0000 |
---|---|---|
committer | PJ Fanning <fanningpj@apache.org> | 2024-10-15 16:13:17 +0000 |
commit | fad6cae019d3dbca9c143855d77f4d2b11c6df3b (patch) | |
tree | 8f0c2b7c85188bdc064929daf085f0672ec7f9db /poi-excelant/src/main/java | |
parent | 88a0d4ecf322be33b7df3ebfc21eff1f176a4efb (diff) | |
download | poi-fad6cae019d3dbca9c143855d77f4d2b11c6df3b.tar.gz poi-fad6cae019d3dbca9c143855d77f4d2b11c6df3b.zip |
try to make ExcelAntWorkbookUtilFactory thread safe
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1921338 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'poi-excelant/src/main/java')
-rw-r--r-- | poi-excelant/src/main/java/org/apache/poi/ss/excelant/util/ExcelAntWorkbookUtilFactory.java | 20 |
1 files changed, 9 insertions, 11 deletions
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<String, ExcelAntWorkbookUtil> workbookUtilMap; + private static final Map<String, ExcelAntWorkbookUtil> 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; } } |