It prints out T1T1T3.
This is both what I expected, and what it did. Note however I wasn't so confident that I posted my response without trying it!
Anyway, why?
We create a new
thread (new B(), "T1") which is called T1.
The run method is invoked (on a new stack) with the start call. This new stack, called T1, immediately creates an A and calls run. It does not create a thread, it just calls run, so there is no new stack frame. It is not a new thread, and prints out the current thread name T1.
Next, we create a new thread A, but again we do not call start. We call the run method on the thread. From the sun docs:
run()
If this thread was constructed using a separate Runnable run object, then that Runnable object's run method is called; otherwise, this method does nothing and returns.
So this calls the run method of A- which prints out T1- there is no new stack frame for T2. If you change it to a start() call you get T1T2T3, but since we didn't, we get T1.
Finally, we call the new thread correctly, and create a thread which gets its own stack frame with the start() call. When the run method is executed now it finds the new name of the thread T3.