What is happening in the background if I do this:
class TestThread {
public static void main(String[] args) {
Thread t = new Thread();
t.start();
System.out.println(t.getName());
}
}
I know that to create a new thread you must override the run()
method by either extending the Thread
class or by implementing the Runnable
interface.
If we implement the Runnable
interface we have to provide the target run method where the code which has to run concurrently is provided.
Also, If we do not override the run()
method and do not extend the Thread
or implement the Runnable
, the main()
thread will execute.
I would like to know as to what exactly will happen in the background when I execute the above code? Does the main have a run()
method like other Thread
s? Will this create a new Thread
in addition to the main
thread?