There are two ways of Thread creation either by implementing Runnable or extending the Thread class. In both the cases you need to start the thread for getting the functionality you need. So in order to start a thread we need a method which is start() and it is invoked on Thread object.
Remember:-start() method is always invoked on Thread object to start a separate call stack of this thread,but if you call the run() method on your Runnable object then it is simply a method call and cannot initiate a separate call stack. It also clears that You start a Thread not a Runnable.
To start a new Thread in separate call stack use
t. start() // where t is Thread object which is in execution.
We have made a call to start() method but know what happens behind the scenes there are three things happen:-
- A new Thread in execution starts(in a new call stack).
- The Thread moves from the new state to the runnable state.
- Whenever the Thread gets a chance to execute then it goes to running state and the target run() method will run.
Consider the following example to understand how Threads are started and also you will come to know that invoking run() method do works but it never ever initiate a new Thread or a separate call stack.
class TestRunnable implements Runnable
{
public void run()
{
for(int i=0;i<5;i++)
System. out. println(”In Runnable”);
}
public static void main(String a[])
{
Thread tr = Thread. currentThread();
System. out. println(tr);
TestRunnable r = new TestRunnable();
Thread t = new Thread(r);
System. out. println(r);
r. run();
System. out. println(t);
t. start();
}
}
OutPut:-
Thread[main,5,main]
TestRunnable@3e25a5
In Runnable
In Runnable
Thread[First Thread,5,main]
In Runnable
In Runnable
Explanations:-
Here in above example there are two things we wanted to get you know that new Threads are started by calling start() method on Thread object and Runnable can never ever start a new call stack. invoking run() method simply works as another method invocation. Also you can see that when we tried to print the names of Threads then r comes with only as object names whereas the Thread t and tr have original Thread names.

