<div dir="ltr"><div>Hello! In this topic, I'd like to discuss the following scenario with an AWT/Swing application:<br>1. The system is shutting down, or the user is logging out.</div><div>
2. The application's background thread posts a UI-related task onto the EDT (via <i>invokeLater</i>).<br>3. As a consequence of p.1, the WToolkit's runtime shutdown hook gets launched (the thread called "<i>ToolkitShutdown</i>"), which signals the WToolkit's event loop to exit.</div><div>4. As a consequence of p.3, the WToolkit's event loop exits, and then <i>AwtToolkit::Dispose()</i> gets called.<br>5. EDT starts performing the task posted in p.2. The task happens to (indirectly) call some AWT native API, e.g. <i>WComponentPeer.getLocationOnScreen</i>.<br>6. All such API natively starts with <i>hang_if_shutdown()</i>, causing EDT to hang forever.<br>7. The hanging non-daemon thread causes the system to pause and then cancel by timeout the shutting down/logging out routine.<br><br>I understand that this AWT behavior is kind of supposed, but <i><u>it turns out that the application somehow has to understand that the WToolkit's shutdown hook is about to launch and manage to finish all its EDT activities before the hook gets actually</u></i><i><u> launched. What is the intended way to do so?</u></i> As far as I understand, registering your own hook is not an option because:<br>1. The order of their execution is not specified/guaranteed</div><div>2. It's still not possible to immediately shut down the EDT (because the hook is still another thread and you'll still need <i>invokeLater</i>).</div><div><br>Thank you in advance for help!<br><br></div><div><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr">Best regards,<div>Nikita Provotorov</div></div></div></div></div>