Click here to watch in Youtube :
https://www.youtube.com/watch?v=8d8FrwgSkIw&list=UUhwKlOVR041tngjerWxVccw
Click the below Image to Enlarge
Java Tutorial : Java Threads (What if we call the run() method directly instead of start() method) |
Java Tutorial : Java Threads (What if we call the run() method directly instead of start() method) |
class DisplayThread extends Thread { public static void main(String args[]) { DisplayThread displayThread = new DisplayThread(); /* * fine, but does not start a separate call stack */ displayThread.run(); } public void run() { System.out.println("Hello by "); } }
Hello byDisplayNumberThread.java
public class DisplayNumberThread extends Thread { public static void main(String[] args) { DisplayNumberThread displayNumberThread1 = new DisplayNumberThread(); DisplayNumberThread displayNumberThread2 = new DisplayNumberThread(); displayNumberThread1.run(); displayNumberThread2.run(); } public void run() { for (int i = 1; i < 5; i++) { try { Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } System.out.println(i); } } }
1 2 3 4 1 2 3 4Click the below link to download the code:
https://sites.google.com/site/ramj2eev1/home/javabasics/ThreadDemo_run_directly_app.zip?attredirects=0&d=1
Github Link:
https://github.com/ramram43210/Java/tree/master/BasicJava/ThreadDemo_run_directly_app
Bitbucket Link:
https://bitbucket.org/ramram43210/java/src/7d3f471503184934dd2cdb3cf35260480f18e932/BasicJava/ThreadDemo_run_directly_app/?at=master
See also:
No comments:
Post a Comment