src/java.desktop/unix/classes/sun/awt/X11/XRootWindow.java

Print this page

        

@@ -29,24 +29,28 @@
  * This class represents AWT application root window functionality.
  * Object of this class is singleton, all window reference it to have
  * common logical ancestor
  */
 class XRootWindow extends XBaseWindow {
-    private static XRootWindow xawtRootWindow = null;
-    static XRootWindow getInstance() {
+    private static class LazyHolder {
+        private static final XRootWindow xawtRootWindow;
+
+        static {
         XToolkit.awtLock();
         try {
-            if (xawtRootWindow == null) {
                 xawtRootWindow = new XRootWindow();
                 xawtRootWindow.init(xawtRootWindow.getDelayedParams().delete(DELAYED));
-            }
-            return xawtRootWindow;
         } finally {
             XToolkit.awtUnlock();
         }
     }
 
+    }
+    static XRootWindow getInstance() {
+        return LazyHolder.xawtRootWindow;
+    }
+
     private XRootWindow() {
         super(new XCreateWindowParams(new Object[] { DELAYED, Boolean.TRUE,
                                                      EVENT_MASK, XConstants.StructureNotifyMask }));
     }