< prev index next >

src/java.desktop/windows/classes/sun/awt/windows/WToolkit.java

Print this page

        

@@ -70,10 +70,12 @@
 
 import java.util.Hashtable;
 import java.util.Locale;
 import java.util.Map;
 import java.util.Properties;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
 
 import sun.awt.util.PerformanceLogger;
 import sun.font.FontManager;
 import sun.font.FontManagerFactory;
 import sun.font.SunFontManager;

@@ -808,26 +810,39 @@
         if (lge instanceof DisplayChangedListener) {
             ((DisplayChangedListener) lge).paletteChanged();
         }
     }
 
+    private static ExecutorService displayChangeExecutor;
+
     /*
      * Called from Toolkit native code when a WM_DISPLAYCHANGE occurs.
      * Have Win32GraphicsEnvironment execute the display change code on the
      * Event thread.
      */
     public static void displayChanged() {
-        EventQueue.invokeLater(new Runnable() {
-            @Override
-            public void run() {
+        final Runnable runnable = () -> {
                 Object lge = GraphicsEnvironment.getLocalGraphicsEnvironment();
                 if (lge instanceof DisplayChangedListener) {
                     ((DisplayChangedListener) lge).displayChanged();
                 }
-            }
+        };
+        if (AppContext.getAppContext() != null) {
+            // Common case, standalone application
+            EventQueue.invokeLater(runnable);
+        } else {
+            if (displayChangeExecutor == null) {
+                // No synchronization, called on the Toolkit thread only
+                displayChangeExecutor = Executors.newFixedThreadPool(1, r -> {
+                    Thread t = Executors.defaultThreadFactory().newThread(r);
+                    t.setDaemon(true);
+                    return t;
         });
     }
+            displayChangeExecutor.submit(runnable);
+        }
+    }
 
     /**
      * create the peer for a DragSourceContext
      */
 
< prev index next >