Thread.start() creates new thread which is responsible for the execution of run() method. Thread.start() is also responsible to register a thread with thread scheduler.
Importance of Thread.start()?
In java, there is no other way to start a new thread. Only Thread.start() creates new thread which is responsible for the execution of run() method. Thread.start() is also responsible to register a thread with thread scheduler. That’s why, Thread.start() is consider as Heart of Multi-threading.
Overriding start() / Overriding Thread.start()
If we override a Thread.start() method, it will not create a new thread. It will act as normal method.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
class MyThread extends Thread { public void run() { for(int i=0;i<10;i++) { System.out.println("child thread"); } } public void start() { System.out.println("start method"); } } class Main { public static void main(String[] args) { MyThread t=new MyThread(); t.start(); System.out.println("main thread"); } } |
Output:
1 2 |
start method main thread |
Difference between start() and run() in Java?
Thread.start() creates new thread which is responsible for the execution of run() method. Thread.start() is also responsible to register a thread with thread scheduler.
Thread.run() method won’t create new thread and just act as normal method.