From b157a43a59c73b2d60402f6eef2d070563d6919a Mon Sep 17 00:00:00 2001 From: Yana Ilieva Date: Fri, 13 Dec 2024 16:28:47 +0200 Subject: [PATCH] Intern MBean names used in cache 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. --- 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);