PATCH: ShutdownHooks and LoggingDeadlock2

Alan Bateman Alan.Bateman at Sun.COM
Tue Apr 14 12:33:16 UTC 2009


Mandy Chung wrote:
> Hi Martin,
>
> Thanks for catching the regression.  I created a Sun bug # 6829503 for 
> bug 2.
>
> With the fix for 6829503, ApplicationShutdownHook and DeleteOnExitHook 
> are both lazily initialized.  Since it is possible that a file could 
> be added to the list for DeletedOnExit during shutdown, perhaps we 
> also need to change the Shutdown.add method to allow DeleteOnExitHook 
> to be added during shutdown.
> I should pick up this bug since my fix caused this regression.  Or do 
> you want to revise the patch?
>
I also missed this case when reviewing the changes (sorry) but at least 
it has been caught in good time  I think you will need to allow hooks be 
added during the shutdown, if only to allow deleteOnExit to register a 
first file for deletion when invoked from a shutdown hook (I realize 
this isn't the issue that Martin ran into but I see we've got this issue 
also).

One idea is for Shutdown#add to not check the state but instead return a 
boolean to indicate if shutdown is in progress. 
ApplicationShutdownHooks.<clinit> could use this to determine if its 
hooks map should be initialized or not. That way, addShutdownHook will 
behave as expected and throw IllegalStateException during shutdown. If 
addShutdownHook is first invoked during shutdown it will be harmless 
because its runHooks will simply process an empty map. As you said, 
deleteOnExit  also has a problem in that DeleteOnExitHook.<clinit> can 
fail to register its hook. You'll actually be fixing a second (and I 
think unreported) bug that has existed for some time. That bug is that 
deleteOnExit is throwing IllegalStateException during shutdown when it 
shouldn't. That bug has been there for a while but has been masked by 
6526376 (fixed early in jdk7).

-Alan.



More information about the core-libs-dev mailing list