From 4354210e6037208f8651447ef17dbbbb2f878544 Mon Sep 17 00:00:00 2001 From: Yana Ilieva <71656848+yana-ilieva@users.noreply.github.com> Date: Fri, 13 Dec 2024 18:46:54 +0200 Subject: [PATCH] Intern MBean names used in cache (#1098) Use string interning when creating the "matchName" used in the caching data structure, in order to reuse previously created String objects and to avoid duplication of Strings with identical contents in memory. Signed-off-by: Yana Ilieva --- collector/src/main/java/io/prometheus/jmx/JmxCollector.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/collector/src/main/java/io/prometheus/jmx/JmxCollector.java b/collector/src/main/java/io/prometheus/jmx/JmxCollector.java index ebb1eca4..6c0e5e98 100644 --- a/collector/src/main/java/io/prometheus/jmx/JmxCollector.java +++ b/collector/src/main/java/io/prometheus/jmx/JmxCollector.java @@ -581,7 +581,7 @@ public void recordBean( attributeName = attrName; } - String matchName = beanName + attributeName + ": " + matchBeanValue; + String matchName = (beanName + attributeName + ": " + matchBeanValue).intern(); if (rule.cache) { MatchedRule cachedRule = config.rulesCache.get(rule, matchName);