Click here to watch in Youtube :
https://www.youtube.com/watch?v=Rswpkj9ePvc&list=UUhwKlOVR041tngjerWxVccw
Click the below Image to Enlarge
Java Tutorial: Java Threads (Thread join in java | Thread join) |
Java Tutorial: Java Threads (Thread join in java | Thread join) |
class DisplayNumberThread extends Thread { public void run() { for (int i = 1; i <= 5; i++) { try { Thread.sleep(500); } catch (Exception e) { e.printStackTrace(); } System.out.println(this.getName() + " = " +i); } } public static void main(String args[]) { DisplayNumberThread dnt1 = new DisplayNumberThread(); DisplayNumberThread dnt2 = new DisplayNumberThread(); DisplayNumberThread dnt3 = new DisplayNumberThread(); dnt1.start(); try { /* * Waits for this thread to die. */ dnt1.join(); } catch (Exception e) { e.printStackTrace(); } dnt2.start(); dnt3.start(); } }
Thread-0 = 1 Thread-0 = 2 Thread-0 = 3 Thread-0 = 4 Thread-0 = 5 Thread-1 = 1 Thread-2 = 1 Thread-1 = 2 Thread-2 = 2 Thread-1 = 3 Thread-2 = 3 Thread-2 = 4 Thread-1 = 4 Thread-2 = 5 Thread-1 = 5
https://sites.google.com/site/ramj2eev1/home/javabasics/ThreadDemo_join_app.zip?attredirects=0&d=1
Github Link:
https://github.com/ramram43210/Java/tree/master/BasicJava/ThreadDemo_join_app
Bitbucket Link:
https://bitbucket.org/ramram43210/java/src/2bc24748fe4193d8423018abb163c74598759d97/BasicJava/ThreadDemo_join_app/?at=master
See also:
No comments:
Post a Comment