RFR: 8378268: Thread.join can wait on Thread, allows joinNanos to be removed

Viktor Klang vklang at openjdk.org
Wed Feb 25 11:05:44 UTC 2026


On Tue, 24 Feb 2026 09:26:09 GMT, Alan Bateman <alanb at openjdk.org> wrote:

>> src/java.base/share/classes/java/lang/Thread.java line 1909:
>> 
>>> 1907:         // ensure there is a notifyAll to wake up waiters when this thread terminates
>>> 1908:         if (this instanceof VirtualThread vthread) {
>>> 1909:             vthread.beforeJoin();
>> 
>> If deemed valuable, we might be able to do something more sophisticated as the proposed solution will trigger notifyAll even if all joiners bailed out due to timeout.
>
> I think it's best to keep it as simple as possible. It's not wrong to notifyAll if there are no waiters so okay if a joiner bails. My concern with doing anything more sophisticated is that it would add counters or other book keeping. It's enough to just avoid the notifyAll when the thread terminates before anyone calls join.

I 100% agree.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/29839#discussion_r2846268901


More information about the core-libs-dev mailing list