diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-timelineservice/src/main/java/org/apache/hadoop/yarn/server/timelineservice/collector/PerNodeTimelineCollectorsAuxService.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-timelineservice/src/main/java/org/apache/hadoop/yarn/server/timelineservice/collector/PerNodeTimelineCollectorsAuxService.java index c15f99d3bb2..dab61589600 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-timelineservice/src/main/java/org/apache/hadoop/yarn/server/timelineservice/collector/PerNodeTimelineCollectorsAuxService.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-timelineservice/src/main/java/org/apache/hadoop/yarn/server/timelineservice/collector/PerNodeTimelineCollectorsAuxService.java @@ -156,15 +156,13 @@ public void initializeContainer(ContainerInitializationContext context) { if (context.getContainerType() == ContainerType.APPLICATION_MASTER) { ApplicationId appId = context.getContainerId(). getApplicationAttemptId().getApplicationId(); - synchronized (appIdToContainerId) { - Set masterContainers = appIdToContainerId.get(appId); - if (masterContainers == null) { - masterContainers = new HashSet<>(); - appIdToContainerId.put(appId, masterContainers); - } - masterContainers.add(context.getContainerId()); - addApplication(appId, context.getUser()); + Set masterContainers = appIdToContainerId.get(appId); + if (masterContainers == null) { + masterContainers = new HashSet<>(); + appIdToContainerId.put(appId, masterContainers); } + masterContainers.add(context.getContainerId()); + addApplication(appId, context.getUser()); } } @@ -189,19 +187,17 @@ protected Future removeApplicationCollector(final ContainerId containerId) { containerId.getApplicationAttemptId().getApplicationId(); return scheduler.schedule(new Runnable() { public void run() { - synchronized (appIdToContainerId) { - Set masterContainers = appIdToContainerId.get(appId); - if (masterContainers == null) { - LOG.info("Stop container for " + containerId - + " is called before initializing container."); - return; - } - masterContainers.remove(containerId); - if (masterContainers.size() == 0) { - // remove only if it is last master container - removeApplication(appId); - appIdToContainerId.remove(appId); - } + Set masterContainers = appIdToContainerId.get(appId); + if (masterContainers == null) { + LOG.info("Stop container for " + containerId + + " is called before initializing container."); + return; + } + masterContainers.remove(containerId); + if (masterContainers.size() == 0) { + // remove only if it is last master container + removeApplication(appId); + appIdToContainerId.remove(appId); } } }, collectorLingerPeriod, TimeUnit.MILLISECONDS);