On Sat, 2 Jul 2022 14:07:57 GMT, Ryan Ernst <d...@openjdk.org> wrote:

>> src/java.base/share/classes/java/lang/Runtime.java line 88:
>> 
>>> 86:      * <p> Invocations of this method block indefinitely. It is 
>>> therefore
>>> 87:      * inadvisable to invoke this method from a shutdown hook as it will
>>> 88:      * cause deadlock.
>> 
>> This is inaccurate. The method only blocks indefinitely when shutdown has 
>> already commenced.
>
> If a shutdown hook is running, then shutdown has started, right? This new 
> wording isn’t really a change, it’s the current behavior (the “otherwise” 
> portion of the old wording). But the wording is meant to be more accurate for 
> the case of running exit from shutdown hooks. The change is the removal of 
> the first case, which is what the code portion of the PR removes.

The first paragraph of the method description already makes it clear that the 
method never returns normally. One option for the third paragraph is to just 
remove it, another is to replace it with wording that specifies that the first 
thread to call exit is the winner and the exit code provided by other threads 
that attempt to exit around the same time (or while exit hooks execute) will be 
ignored. I think there is merit with adding a warning that a shutdown hook 
invoking exit will deadlock.

-------------

PR: https://git.openjdk.org/jdk/pull/9351

Reply via email to