Code :
public class ThreadNaming extends Thread{
public void run()
{
System.out.println("running");
}
public static void main(String[] args)
{
ThreadNaming t1 = new ThreadNaming();
t1.start();
System.out.println(t1.getName());
}
}
Doubt : According to my understanding a thread starts executing the main function , once t1.start()
is encountered a new call stack and a new thread is created . This newly created thread executes the run method , then control returns to original thread executing the main()
function and next System.out.println(t1.getName())
is executed so according to this flow output should be :
running
Thread-0
but eclipse is showing the following output
Thread-0
running
I have googled flow control of thread but didnt get anything and i am unable to understand why this is happening ? can anyone explain the reason for it with proper flow of control ?
Note : Thread-0 is name of thread
Unique Part : i don't want to implement the behaviour described in the other question , i want to know the reason how main thread and new thread are executing simultaneously because i read in a tutorial that a scheduler can only execute a single thread at a time .