On Sun, 28 Aug 2022 22:20:03 GMT, David Holmes <dhol...@openjdk.org> wrote:

>> src/java.base/share/classes/java/lang/Thread.java line 70:
>> 
>>> 68:  * The newly started thread invokes the task's {@link Runnable#run() 
>>> run} method.
>>> 69:  *
>>> 70:  * <p> A platform thread <i>terminates</i> if either its {@code run} 
>>> method completes
>> 
>> I don't think the update in 9796557d works. It switches to talking about the 
>> termination of platform threads before we've introduced what a platform 
>> thread is. It also switches to talking about the Thread.run method when the 
>> focus in the previous paragraph has been the the task that the thread 
>> executes. If we really need this here then the second paragraph will need to 
>> explain that it is also possible to extend Thread and override the run 
>> method.
>
> I don't think we need to distinguish between platform and virtual threads 
> here at all. Isn't it the case that virtual threads also have a run() method 
> and they too terminate when run() completes as described (together with UEH)? 
> The fact most Thread run() methods call something else's run() method is 
> immaterial. We don't know what a run() method will do, but whatever it is 
> once it completes then the thread has terminated.

There are subtle differences (invoking a virtual Thread's run method directly 
does no nothing) but that is too much detail and would confusing to say 
anything about in the introduction paragraphs.

The following is closer to what I think we should have. The existing paragraph 
2 describes starting a thread so this is where the Thread.run method is 
introduced. Paragraph 3 follows to describe termination.


 * <p> {@code Thread} defines constructors and a {@link Builder} to create 
threads.
 * {@linkplain #start() Starting} a thread schedules the newly started thread 
to execute
 * its {@link #run() run} method. The thread executes concurrently with the 
thread that
 * caused it to start.
 *
 * <p> A thread <i>terminates</i> if either its {@code run} method completes 
normally,
 * or if its {@code run} method completes abruptly and the appropriate 
{@linkplain
 * Thread.UncaughtExceptionHandler uncaught exception handler} completes 
normally or
 * abruptly. With no code left to run, the thread has completed execution. 
Thread
 * defines the {@link #join() join} method to wait for a thread to terminate.

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

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

Reply via email to