JDK-6301682 : EventQueue should prevent usage during shutdown hook
  • Type: Enhancement
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 6
  • Priority: P4
  • Status: Closed
  • Resolution: Won't Fix
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2005-07-26
  • Updated: 2011-01-19
  • Resolved: 2008-12-05
Related Reports
Relates :  
Relates :  
Description
A DESCRIPTION OF THE REQUEST :
EventQueue.invokeLater() and EventQueue.invokeAndWait() should throw an exception in case it is invoked from a shutdown thread.

This exception should be documented and become part of the new spec (so yes, we're modifying the API specification) but I don't think that this is breaking backwards compatibility because the current behavior is that instead of throwing an exception a deadlock will occur.

JUSTIFICATION :
If an application registers a shutdown hook, it is able to know not to rely on the EventQueue (i.e. don't invoke JFrame.dispose()) but 3rd party libraries have absolutely no way of finding out whether they're running inside a shutdown hook or not.

The only way to prevent deadlocks from occuring is to throw an exception which signals that we're inside a shutdown hook (or the EventQueue is otherwise unavailable).

This will allow libraries to catch the exception and continue shutting down without interacting with AWT components. For example, temporarily files can be removed, etc... without closing windows.

Comments
EVALUATION Closing this CR as 'will not fix', because a) it can't be implemented in a grace way b) Runtime.addShutdownHook() explicitly warn developers not to use any services like AWT event dispatch thread from shutdown hooks.
05-12-2008

EVALUATION At the current moment I don't see any way for AWT (or EventQueue class) to detect if it is called while JVM shutdown is started, or not. That's why I consider it is a responsibility of application developer to make sure no AWT code, directly or *indirectly*, is called from shutdown hooks. I have also found we can't implement the requested behavior even for auto-shutdown case, for example, discard all the EventQueue.postEvent() calls after AWTAutoShutdown has released its non-daemon blocker thread. We can't do this, because AWTAutoShutdown is implemented that way, so AWT can be re-launched again, for example, from some non-daemon user thread.
09-07-2008

EVALUATION I see two possible scenarios when calling EventQueue API from a shutdown hook: throw an exception or just do nothing. Whatever scenario is selected, it should be documented.
03-06-2008

EVALUATION Note a fix for this CR depends on a fix for 6261550. *** (#1 of 1): [ UNSAVED ] ###@###.###
26-07-2005