With the help of a call to the method start() the thread is started and the further execution is transferred to the method run. start is terminated after starting the thread and the caller can continue in parallel with the newly created thread.
public class MyThread extends Thread {
public void run() {
System.out.println("Thread is running");
}
public static void main(String[] args) {
MyThread thread = new MyThread();
thread.start();
}
}
Thread is running
public class MyThread implements Runnable {
public void run() {
System.out.println("Thread is running");
}
public static void main(String[] args) {
MyThread obj = new MyThread();
Thread thread = new Thread(obj);
thread.start();
}
}
Thread is running