Friday, 16 December 2016

Java Tutorial: Java Threads (Thread join in java | Thread join)


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) 
DisplayNumberThread.java
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();
    }
}
Output
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

Click the below link to download the code:
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:
  • All JavaEE Viedos Playlist
  • All JavaEE Viedos
  • All JAVA EE Links
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • Java Collection Framework Tutorial
  • JAVA Tutorial
  • Kids Tutorial
  • No comments:

    Post a Comment

    Google+ Followers

    Google+ Badge