posted 1 month ago
The API documentation for the Thread class contains many, many instances of the phrase "current thread". But it never gets around to saying what that means. Perhaps the writers thought it was too obvious to mention.
It looks like you've found an example which shows why it isn't that obvious. Basically, the documentation of Thread goes on and on about the "current thread" without mentioning that it's a thread, a native resource in the JVM, and not a Thread object. The two concepts are different. Once a Thread's start() method is called, that Thread object is associated with a thread. The start() method calls the run() method which is associated with the Thread object and from then on, every time that code in that Thread calls Thread.currentThread(), it gets a reference to itself.
But before the Thread object becomes associated with a thread by having its start() method called, a call to Thread.currentThread() can't return a reference to that object because it isn't associated with any thread. Some other thread is the current thread. Your example shows this in action.