|
27 | 27 | import java.util.Map; |
28 | 28 | import java.util.Set; |
29 | 29 | import java.util.concurrent.atomic.AtomicBoolean; |
| 30 | +import java.util.concurrent.locks.ReentrantLock; |
30 | 31 | import javax.xml.parsers.DocumentBuilder; |
31 | 32 | import javax.xml.parsers.DocumentBuilderFactory; |
32 | 33 | import javax.xml.parsers.ParserConfigurationException; |
@@ -67,6 +68,8 @@ public enum CustomizeConfiguration { |
67 | 68 | private static final Map<String, ElementMatcher> CONTEXT_ENHANCE_CLASSES = new HashMap<>(); |
68 | 69 | private static final AtomicBoolean LOAD_FOR_CONFIGURATION = new AtomicBoolean(false); |
69 | 70 |
|
| 71 | + private static volatile List<Map<String, Object>> RESOLVED_FILE_CONFIGURATIONS; |
| 72 | + private static final ReentrantLock RESOLVED_FILE_LOCK = new ReentrantLock(); |
70 | 73 | /** |
71 | 74 | * The loadForEnhance method is resolver configuration file, and parse it |
72 | 75 | */ |
@@ -107,13 +110,26 @@ public synchronized void loadForConfiguration() { |
107 | 110 | * @throws SAXException link {@link SAXException} |
108 | 111 | */ |
109 | 112 | private List<Map<String, Object>> resolver() throws ParserConfigurationException, IOException, SAXException { |
110 | | - List<Map<String, Object>> customizeMethods = new ArrayList<Map<String, Object>>(); |
111 | | - File file = new File(CustomizePluginConfig.Plugin.Customize.ENHANCE_FILE); |
112 | | - if (file.exists() && file.isFile()) { |
113 | | - NodeList classNodeList = resolverFileClassDesc(file); |
114 | | - resolverClassNodeList(classNodeList, customizeMethods); |
| 113 | + if (RESOLVED_FILE_CONFIGURATIONS != null) { |
| 114 | + return RESOLVED_FILE_CONFIGURATIONS; |
115 | 115 | } |
116 | | - return customizeMethods; |
| 116 | + |
| 117 | + RESOLVED_FILE_LOCK.lock(); |
| 118 | + try { |
| 119 | + if (RESOLVED_FILE_CONFIGURATIONS != null) { |
| 120 | + return RESOLVED_FILE_CONFIGURATIONS; |
| 121 | + } |
| 122 | + List<Map<String, Object>> customizeMethods = new ArrayList<Map<String, Object>>(); |
| 123 | + File file = new File(CustomizePluginConfig.Plugin.Customize.ENHANCE_FILE); |
| 124 | + if (file.exists() && file.isFile()) { |
| 125 | + NodeList classNodeList = resolverFileClassDesc(file); |
| 126 | + resolverClassNodeList(classNodeList, customizeMethods); |
| 127 | + } |
| 128 | + RESOLVED_FILE_CONFIGURATIONS = customizeMethods; |
| 129 | + } finally { |
| 130 | + RESOLVED_FILE_LOCK.unlock(); |
| 131 | + } |
| 132 | + return RESOLVED_FILE_CONFIGURATIONS; |
117 | 133 | } |
118 | 134 |
|
119 | 135 | /** |
|
0 commit comments