From 793b7bd8cf362c508b38e94c82355c87e436a073 Mon Sep 17 00:00:00 2001 From: Jean-Louis Monteiro Date: Mon, 30 Oct 2023 14:59:21 +0100 Subject: [PATCH] feat(#TOMEE-4267): MicroProfile Metrics JMX Registrar must be initialized once --- .../metrics/MPMetricsCDIExtension.java | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/tomee/tomee-microprofile/mp-common/src/main/java/org/apache/tomee/microprofile/metrics/MPMetricsCDIExtension.java b/tomee/tomee-microprofile/mp-common/src/main/java/org/apache/tomee/microprofile/metrics/MPMetricsCDIExtension.java index a058238c91e..f406c9614e6 100644 --- a/tomee/tomee-microprofile/mp-common/src/main/java/org/apache/tomee/microprofile/metrics/MPMetricsCDIExtension.java +++ b/tomee/tomee-microprofile/mp-common/src/main/java/org/apache/tomee/microprofile/metrics/MPMetricsCDIExtension.java @@ -24,15 +24,23 @@ import org.apache.openejb.util.LogCategory; import org.apache.openejb.util.Logger; +import java.io.IOException; +import java.util.concurrent.atomic.AtomicBoolean; + public class MPMetricsCDIExtension implements Extension { + private static final AtomicBoolean INIT = new AtomicBoolean(false); + private void afterDeploymentValidation(@Observes final AfterDeploymentValidation avd, BeanManager bm) { - try { - final JmxRegistrar registrar = new JmxRegistrar(); - registrar.init(); - } catch (final Exception e) { - Logger.getInstance(LogCategory.OPENEJB, MPMetricsCDIExtension.class).error("Can't initialize Metrics Registrar: " + e.getMessage()); + if (INIT.compareAndSet(false, true)) { + try { + final JmxRegistrar registrar = new JmxRegistrar(); + registrar.init(); + + } catch (final IOException e) { + Logger.getInstance(LogCategory.OPENEJB, MPMetricsCDIExtension.class).error("Can't initialize Metrics Registrar: " + e.getMessage()); + } } }