p-szucs commented on code in PR #6821:
URL: https://github.com/apache/hadoop/pull/6821#discussion_r1599517841


##########
hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/linux/resources/ResourceHandlerModule.java:
##########
@@ -63,35 +63,54 @@ public class ResourceHandlerModule {
    * as resource metrics functionality. We need to ensure that the same
    * instance is used for both.
    */
+  private static volatile CGroupsHandler cGroupsV1Handler;
+  private static volatile CGroupsHandler cGroupsV2Handler;
   private static volatile TrafficControlBandwidthHandlerImpl
       trafficControlBandwidthHandler;
   private static volatile NetworkPacketTaggingHandlerImpl
       networkPacketTaggingHandlerImpl;
-  private static volatile CGroupsHandler cGroupsHandler;
   private static volatile CGroupsBlkioResourceHandlerImpl
       cGroupsBlkioResourceHandler;
   private static volatile MemoryResourceHandler
       cGroupsMemoryResourceHandler;
   private static volatile CpuResourceHandler
       cGroupsCpuResourceHandler;
 
-  /**
-   * Returns an initialized, thread-safe CGroupsHandler instance.
-   */
-  private static CGroupsHandler getInitializedCGroupsHandler(Configuration 
conf)
+  private static void initializeCGroupsHandlers(Configuration conf) throws 
ResourceHandlerException {
+    initializeCGroupsV1Handler(conf);
+    if (cgroupsV2Enabled) {
+      initializeCGroupsV2Handler(conf);
+    }
+  }
+
+  private static void initializeCGroupsV1Handler(Configuration conf)
       throws ResourceHandlerException {
-    if (cGroupsHandler == null) {
+    if (cGroupsV1Handler == null) {
       synchronized (CGroupsHandler.class) {
-        if (cGroupsHandler == null) {
-          cGroupsHandler = cgroupsV2Enabled
-              ? new CGroupsV2HandlerImpl(conf, 
PrivilegedOperationExecutor.getInstance(conf))
-              : new CGroupsHandlerImpl(conf, 
PrivilegedOperationExecutor.getInstance(conf));
-          LOG.debug("Value of CGroupsHandler is: {}", cGroupsHandler);
+        if (cGroupsV1Handler == null) {

Review Comment:
   It catched my eye too, but then I found that it is implemented based on the 
double-checked locking, so I left it there: 
https://www.baeldung.com/java-singleton-double-checked-locking



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to