/*
 *  eXist Open Source Native XML Database
 *  Copyright (C) 2001-07 The eXist Project
 *  http://exist-db.org
 *
 *  This program is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public License
 *  as published by the Free Software Foundation; either version 2
 *  of the License, or (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 * $Id$
 */
package org.exist.management;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

public class AgentFactory {

    private final static Logger LOG = LogManager.getLogger(AgentFactory.class);

    private static Agent instance = null;

    public static Agent getInstance() {
        if (instance == null) {
            final String className = System.getProperty("exist.jmxagent", "org.exist.management.impl.JMXAgent");
            try {
                final Class<?> clazz = Class.forName(className);
                if (!Agent.class.isAssignableFrom(clazz)) {
                    LOG.warn("Class " + className + " does not implement interface Agent. Using fallback.");
                } else {
                    instance = (Agent) clazz.newInstance();
                }
            } catch (final ClassNotFoundException e) {
                LOG.warn("Class not found for JMX agent: " + className);
            } catch (final IllegalAccessException | InstantiationException e) {
                LOG.warn("Failed to instantiate class for JMX agent: " + className);
            }
            if (instance == null)
                {instance = new DummyAgent();}
        }
        return instance;
    }
}

@@ -901,16 +901,56 @@
 ement;%0A%0A
+import net.jcip.annotations.ThreadSafe;%0A
 import o
@@ -1026,16 +1026,28 @@
 ogger;%0A%0A
+@ThreadSafe%0A
 public c
@@ -1205,24 +1205,37 @@
 blic static 
+synchronized 
 Agent getIns

Make AgentFactory thread-safe