diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/metrics2/lib/MutableQuantiles.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/metrics2/lib/MutableQuantiles.java index a4711db3503..5b12370536a 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/metrics2/lib/MutableQuantiles.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/metrics2/lib/MutableQuantiles.java @@ -23,6 +23,7 @@ import static org.apache.hadoop.metrics2.lib.Interns.info; import java.util.Map; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.ScheduledFuture; import java.util.concurrent.TimeUnit; import org.apache.commons.lang.StringUtils; @@ -57,6 +58,7 @@ public class MutableQuantiles extends MutableMetric { private QuantileEstimator estimator; private long previousCount = 0; + private ScheduledFuture scheduledTask = null; @VisibleForTesting protected Map previousSnapshot = null; @@ -105,8 +107,8 @@ public class MutableQuantiles extends MutableMetric { estimator = new SampleQuantiles(quantiles); this.interval = interval; - scheduler.scheduleAtFixedRate(new RolloverSample(this), interval, interval, - TimeUnit.SECONDS); + scheduledTask = scheduler.scheduleAtFixedRate(new RolloverSample(this), + interval, interval, TimeUnit.SECONDS); } @Override @@ -135,6 +137,13 @@ public class MutableQuantiles extends MutableMetric { return interval; } + public void stop() { + if (scheduledTask != null) { + scheduledTask.cancel(false); + } + scheduledTask = null; + } + public synchronized void setEstimator(QuantileEstimator quantileEstimator) { this.estimator = quantileEstimator; } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/monitor/ContainerMetrics.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/monitor/ContainerMetrics.java index 31a9aa75b86..07b3deadc4d 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/monitor/ContainerMetrics.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/monitor/ContainerMetrics.java @@ -250,6 +250,8 @@ public class ContainerMetrics implements MetricsSource { timer = null; } scheduleTimerTaskForUnregistration(); + this.pMemMBQuantiles.stop(); + this.cpuCoreUsagePercentQuantiles.stop(); } }