diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/monitoring/TaskMonitor.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/monitoring/TaskMonitor.java index 728d89d8e53..1281613a88f 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/monitoring/TaskMonitor.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/monitoring/TaskMonitor.java @@ -73,8 +73,9 @@ public class TaskMonitor { new Class[] { MonitoredTask.class }, new PassthroughInvocationHandler(stat)); TaskAndWeakRefPair pair = new TaskAndWeakRefPair(stat, proxy); - synchronized (this) { - tasks.add(pair); + tasks.add(pair); + if (tasks.size() > MAX_TASKS) { + purgeExpiredTasks(); } return proxy; } @@ -87,8 +88,9 @@ public class TaskMonitor { new Class[] { MonitoredRPCHandler.class }, new PassthroughInvocationHandler(stat)); TaskAndWeakRefPair pair = new TaskAndWeakRefPair(stat, proxy); - synchronized (this) { - tasks.add(pair); + tasks.add(pair); + if (tasks.size() > MAX_TASKS) { + purgeExpiredTasks(); } return proxy; }