HADOOP-7529. Fix lock cycles in metrics system. (llu)

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1157187 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Luke Lu 2011-08-12 16:57:23 +00:00
parent d5ef72e8c1
commit 7d612e9325
2 changed files with 13 additions and 10 deletions

View File

@ -493,6 +493,8 @@ Trunk (unreleased changes)
HADOOP-6622. Token should not print the password in toString. (eli)
HADOOP-7529. Fix lock cycles in metrics system. (llu)
Release 0.22.0 - Unreleased
INCOMPATIBLE CHANGES

View File

@ -18,6 +18,7 @@
package org.apache.hadoop.metrics2.lib;
import java.util.concurrent.atomic.AtomicReference;
import javax.management.ObjectName;
import org.apache.hadoop.classification.InterfaceAudience;
@ -34,7 +35,8 @@
public enum DefaultMetricsSystem {
INSTANCE; // the singleton
private MetricsSystem impl = new MetricsSystemImpl();
private AtomicReference<MetricsSystem> impl =
new AtomicReference<MetricsSystem>(new MetricsSystemImpl());
volatile boolean miniClusterMode = false;
final UniqueNames mBeanNames = new UniqueNames();
final UniqueNames sourceNames = new UniqueNames();
@ -48,8 +50,8 @@ public static MetricsSystem initialize(String prefix) {
return INSTANCE.init(prefix);
}
synchronized MetricsSystem init(String prefix) {
return impl.init(prefix);
MetricsSystem init(String prefix) {
return impl.get().init(prefix);
}
/**
@ -66,8 +68,9 @@ public static void shutdown() {
INSTANCE.shutdownInstance();
}
synchronized void shutdownInstance() {
if (impl.shutdown()) {
void shutdownInstance() {
boolean last = impl.get().shutdown();
if (last) synchronized(this) {
mBeanNames.map.clear();
sourceNames.map.clear();
}
@ -78,13 +81,11 @@ public static MetricsSystem setInstance(MetricsSystem ms) {
return INSTANCE.setImpl(ms);
}
synchronized MetricsSystem setImpl(MetricsSystem ms) {
MetricsSystem old = impl;
impl = ms;
return old;
MetricsSystem setImpl(MetricsSystem ms) {
return impl.getAndSet(ms);
}
synchronized MetricsSystem getImpl() { return impl; }
MetricsSystem getImpl() { return impl.get(); }
@InterfaceAudience.Private
public static void setMiniClusterMode(boolean choice) {