Java / Java Multithreading
Why do we call Thread.start() method which in turns calls run method?
run() method can be called directly however it will not be executing the method under new thread instead the method gets run on current thread.
When start() method is called it invokes run() by create a new Thread.
package com.tutorials.threading; public class ThreadExtended extends Thread { public void run() { System.out.println(String.format("The thread %s execute this line.", Thread.currentThread().getName())); } public static void main(String args[]) { ThreadExtended myThreadObj = new ThreadExtended(); myThreadObj.run(); // called my main Thread myThreadObj.start(); // called my new Thread } }
More Related questions...