You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by wu...@apache.org on 2024/11/28 09:05:38 UTC
(skywalking-java) branch main updated: Improve CustomizeConfiguration by avoiding repeatedly resolve file config (#730)
This is an automated email from the ASF dual-hosted git repository.
wusheng pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/skywalking-java.git
The following commit(s) were added to refs/heads/main by this push:
new 2059fd4cb7 Improve CustomizeConfiguration by avoiding repeatedly resolve file config (#730)
2059fd4cb7 is described below
commit 2059fd4cb7f14f9c704cd82ddb81026b4315cf42
Author: jiangyuan <jo...@gmail.com>
AuthorDate: Thu Nov 28 17:05:32 2024 +0800
Improve CustomizeConfiguration by avoiding repeatedly resolve file config (#730)
---
CHANGES.md | 1 +
.../customize/conf/CustomizeConfiguration.java | 28 +++++++++++++++++-----
2 files changed, 23 insertions(+), 6 deletions(-)
diff --git a/CHANGES.md b/CHANGES.md
index c80b2ac858..8275c7e0fa 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -11,6 +11,7 @@ Release Notes.
* Add witness class/method for resteasy-server plugin(v3/v4/v6)
* Add async-profiler feature for performance analysis
* Support db.instance tag,db.collection tag and AggregateOperation span for mongodb plugin(3.x/4.x)
+* Improve CustomizeConfiguration by avoiding repeatedly resolve file config
All issues and pull requests are [here](https://github.com/apache/skywalking/milestone/222?closed=1)
diff --git a/apm-sniffer/optional-plugins/customize-enhance-plugin/src/main/java/org/apache/skywalking/apm/plugin/customize/conf/CustomizeConfiguration.java b/apm-sniffer/optional-plugins/customize-enhance-plugin/src/main/java/org/apache/skywalking/apm/plugin/customize/conf/CustomizeConfiguration.java
index ba48a9280e..ba3dd5f843 100644
--- a/apm-sniffer/optional-plugins/customize-enhance-plugin/src/main/java/org/apache/skywalking/apm/plugin/customize/conf/CustomizeConfiguration.java
+++ b/apm-sniffer/optional-plugins/customize-enhance-plugin/src/main/java/org/apache/skywalking/apm/plugin/customize/conf/CustomizeConfiguration.java
@@ -27,6 +27,7 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.locks.ReentrantLock;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
@@ -67,6 +68,8 @@ public enum CustomizeConfiguration {
private static final Map<String, ElementMatcher> CONTEXT_ENHANCE_CLASSES = new HashMap<>();
private static final AtomicBoolean LOAD_FOR_CONFIGURATION = new AtomicBoolean(false);
+ private static volatile List<Map<String, Object>> RESOLVED_FILE_CONFIGURATIONS;
+ private static final ReentrantLock RESOLVED_FILE_LOCK = new ReentrantLock();
/**
* The loadForEnhance method is resolver configuration file, and parse it
*/
@@ -107,13 +110,26 @@ public enum CustomizeConfiguration {
* @throws SAXException link {@link SAXException}
*/
private List<Map<String, Object>> resolver() throws ParserConfigurationException, IOException, SAXException {
- List<Map<String, Object>> customizeMethods = new ArrayList<Map<String, Object>>();
- File file = new File(CustomizePluginConfig.Plugin.Customize.ENHANCE_FILE);
- if (file.exists() && file.isFile()) {
- NodeList classNodeList = resolverFileClassDesc(file);
- resolverClassNodeList(classNodeList, customizeMethods);
+ if (RESOLVED_FILE_CONFIGURATIONS != null) {
+ return RESOLVED_FILE_CONFIGURATIONS;
}
- return customizeMethods;
+
+ RESOLVED_FILE_LOCK.lock();
+ try {
+ if (RESOLVED_FILE_CONFIGURATIONS != null) {
+ return RESOLVED_FILE_CONFIGURATIONS;
+ }
+ List<Map<String, Object>> customizeMethods = new ArrayList<Map<String, Object>>();
+ File file = new File(CustomizePluginConfig.Plugin.Customize.ENHANCE_FILE);
+ if (file.exists() && file.isFile()) {
+ NodeList classNodeList = resolverFileClassDesc(file);
+ resolverClassNodeList(classNodeList, customizeMethods);
+ }
+ RESOLVED_FILE_CONFIGURATIONS = customizeMethods;
+ } finally {
+ RESOLVED_FILE_LOCK.unlock();
+ }
+ return RESOLVED_FILE_CONFIGURATIONS;
}
/**