diff --git a/jetty-jmx/src/main/java/org/eclipse/jetty/jmx/MBeanContainer.java b/jetty-jmx/src/main/java/org/eclipse/jetty/jmx/MBeanContainer.java index bc2578857db..f1f0637d600 100644 --- a/jetty-jmx/src/main/java/org/eclipse/jetty/jmx/MBeanContainer.java +++ b/jetty-jmx/src/main/java/org/eclipse/jetty/jmx/MBeanContainer.java @@ -23,6 +23,9 @@ import java.util.HashMap; import java.util.Locale; import java.util.Map; import java.util.WeakHashMap; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentMap; +import java.util.concurrent.atomic.AtomicInteger; import javax.management.InstanceNotFoundException; import javax.management.MBeanRegistrationException; @@ -42,10 +45,15 @@ import org.eclipse.jetty.util.log.Logger; public class MBeanContainer implements Container.InheritedListener, Dumpable { private final static Logger LOG = Log.getLogger(MBeanContainer.class.getName()); + private final static ConcurrentMap __unique = new ConcurrentHashMap(); + public static void resetUnique() + { + __unique.clear(); + } + private final MBeanServer _mbeanServer; private final WeakHashMap _beans = new WeakHashMap(); - private final HashMap _unique = new HashMap(); private String _domain = null; /** @@ -186,11 +194,16 @@ public class MBeanContainer implements Container.InheritedListener, Dumpable buf.append(",").append("name=").append(name); String basis = buf.toString(); - Integer count = _unique.get(basis); - count = count == null ? 0 : 1 + count; - _unique.put(basis, count); - - oname = ObjectName.getInstance(domain + ":" + basis + ",id=" + count); + + AtomicInteger count = __unique.get(basis); + if (count==null) + { + count=__unique.putIfAbsent(basis,new AtomicInteger()); + if (count==null) + count=__unique.get(basis); + } + + oname = ObjectName.getInstance(domain + ":" + basis + ",id=" + count.getAndIncrement()); } ObjectInstance oinstance = _mbeanServer.registerMBean(mbean, oname); diff --git a/jetty-monitor/src/test/java/org/eclipse/jetty/monitor/AttrEventTriggerTest.java b/jetty-monitor/src/test/java/org/eclipse/jetty/monitor/AttrEventTriggerTest.java index 72d60606033..f1416e39fdb 100644 --- a/jetty-monitor/src/test/java/org/eclipse/jetty/monitor/AttrEventTriggerTest.java +++ b/jetty-monitor/src/test/java/org/eclipse/jetty/monitor/AttrEventTriggerTest.java @@ -98,6 +98,7 @@ public class AttrEventTriggerTest _handler = new TestHandler(); _server.setHandler(_handler); + MBeanContainer.resetUnique(); MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer(); _mBeanContainer = new MBeanContainer(mBeanServer); _server.addBean(_mBeanContainer,true);