--- old/src/windows/classes/sun/awt/windows/WToolkit.java 2019-02-21 18:19:40.019111175 +0000 +++ new/src/windows/classes/sun/awt/windows/WToolkit.java 2019-02-21 18:19:39.849110065 +0000 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1996, 2019, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -68,6 +68,8 @@ import java.util.Locale; import java.util.Map; import java.util.Properties; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; import sun.font.FontManager; import sun.font.FontManagerFactory; @@ -828,20 +830,34 @@ .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. */ static public void displayChanged() { - EventQueue.invokeLater(new Runnable() { - @Override - public void run() { - ((Win32GraphicsEnvironment)GraphicsEnvironment - .getLocalGraphicsEnvironment()) - .displayChanged(); + 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); + } } /**