Skip to content

Commit

Permalink
try to make ExcelAntWorkbookUtilFactory thread safe
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1921338 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
pjfanning committed Oct 15, 2024
1 parent 88a0d4e commit fad6cae
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Licensed to the Apache Software Foundation (ASF) under one or more
*/
public final class ExcelAntWorkbookUtilFactory {

private static Map<String, ExcelAntWorkbookUtil> workbookUtilMap;
private static final Map<String, ExcelAntWorkbookUtil> workbookUtilMap = new HashMap<>();

private ExcelAntWorkbookUtilFactory() {
}
Expand All @@ -41,16 +41,14 @@ private 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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Licensed to the Apache Software Foundation (ASF) under one or more
==================================================================== */
package org.apache.poi.xwpf.usermodel;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

Expand Down Expand Up @@ -45,12 +46,14 @@ public enum VerticalAlign {
*/
SUBSCRIPT(3);

private static final Map<Integer, VerticalAlign> imap = new HashMap<>();
private static final Map<Integer, VerticalAlign> imap;

static {
final Map<Integer, VerticalAlign> tempMap = new HashMap<>();
for (VerticalAlign p : values()) {
imap.put(p.getValue(), p);
tempMap.put(p.getValue(), p);
}
imap = Collections.unmodifiableMap(tempMap);
}

private final int value;
Expand Down

0 comments on commit fad6cae

Please sign in to comment.