This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MultiThreading { | |
private static class MyThread extends Thread { | |
public MyThread(String name) { | |
super(name); | |
} | |
@Override | |
public void run() { | |
System.out.println(Thread.currentThread().getName()); | |
} | |
} | |
public static void main(String[] args) { | |
MyThread myThread = new MyThread("myThread"); | |
myThread.run(); | |
} | |
} |
The code above produces the output “main” and not “myThread”. As can be seen in line two of the method, we invoke by mistake the method instead of . Hence, no new thread is started, but the method gets executed within the main thread.
No comments:
Post a Comment