mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
fixed bug & testcase
This commit is contained in:
@@ -43,18 +43,19 @@ import com.alibaba.druid.util.JMXUtils;
|
||||
@SuppressWarnings("rawtypes")
|
||||
public class DruidDataSourceStatManager implements DruidDataSourceStatManagerMBean {
|
||||
|
||||
public final static String SYS_PROP_INSTANCES = "druid.dataSources";
|
||||
public final static String SYS_PROP_INSTANCES = "druid.dataSources";
|
||||
public final static String SYS_PROP_REGISTER_SYS_PROPERTY = "druid.registerToSysProperty";
|
||||
|
||||
private final static Log LOG = LogFactory.getLog(DruidDataSourceStatManager.class);
|
||||
private final static Log LOG = LogFactory.getLog(DruidDataSourceStatManager.class);
|
||||
|
||||
private final static DruidDataSourceStatManager instance = new DruidDataSourceStatManager();
|
||||
private final static DruidDataSourceStatManager instance = new DruidDataSourceStatManager();
|
||||
|
||||
private final AtomicLong resetCount = new AtomicLong();
|
||||
private final AtomicLong resetCount = new AtomicLong();
|
||||
|
||||
// global instances
|
||||
private static IdentityHashMap dataSources;
|
||||
private static volatile IdentityHashMap dataSources;
|
||||
|
||||
private final static String MBEAN_NAME = "com.alibaba.druid:type=DruidDataSourceStat";
|
||||
private final static String MBEAN_NAME = "com.alibaba.druid:type=DruidDataSourceStat";
|
||||
|
||||
public static DruidDataSourceStatManager getInstance() {
|
||||
return instance;
|
||||
@@ -84,14 +85,28 @@ public class DruidDataSourceStatManager implements DruidDataSourceStatManagerMBe
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static IdentityHashMap<Object, ObjectName> getInstances() {
|
||||
public synchronized static IdentityHashMap<Object, ObjectName> getInstances() {
|
||||
if (dataSources == null) {
|
||||
dataSources = getInstances0();
|
||||
if (isRegisterToSystemProperty()) {
|
||||
dataSources = getInstances0();
|
||||
} else {
|
||||
dataSources = new IdentityHashMap<Object, ObjectName>();
|
||||
}
|
||||
}
|
||||
|
||||
return dataSources;
|
||||
}
|
||||
|
||||
public static boolean isRegisterToSystemProperty() {
|
||||
String value = System.getProperty(SYS_PROP_REGISTER_SYS_PROPERTY);
|
||||
|
||||
if ("false".equals(value)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
static IdentityHashMap<Object, ObjectName> getInstances0() {
|
||||
Properties properties = System.getProperties();
|
||||
|
||||
Reference in New Issue
Block a user