Friday, 9 December 2016

Java Tutorial : Java Threads (Thread Sleep | Thread sleep in java)


Click here to watch in Youtube :
https://www.youtube.com/watch?v=qo2SdQhbOc8&list=UUhwKlOVR041tngjerWxVccw

Click the below Image to Enlarge
Java Tutorial : Java Threads (Thread Sleep | Thread sleep in java) 
DisplayThread.java
class DisplayThread extends Thread
{
    public DisplayThread(String threadName)
    {
        super(threadName);
    }

    public static void main(String args[])
    {
        DisplayThread displayThread1 = new DisplayThread("DisplayThread-1");
        DisplayThread displayThread2 = new DisplayThread("DisplayThread-2");

        displayThread1.start();
        displayThread2.start();
    }

    public void run()
    {

        System.out.println("Before sleep of = " + this.getName());
        try
        {
            /*
             * Causes the currently executing thread to
             * sleep (temporarily cease execution) for the
             * specified number of milliseconds, subject to
             * the precision and accuracy of system timers
             * and schedulers. The thread does not lose
             * ownership of any monitors.
             */
            Thread.sleep(10000);
        }
        catch (InterruptedException e)
        {
            e.printStackTrace();
        }
        System.out.println("After sleep of = " + this.getName());
    }

}
Output
Before sleep of = DisplayThread-1
Before sleep of = DisplayThread-2
After sleep of = DisplayThread-2
After sleep of = DisplayThread-1

Click the below link to download the code:
https://sites.google.com/site/ramj2eev1/home/javabasics/ThreadDemo_sleep_App.zip?attredirects=0&d=1

Github Link:
https://github.com/ramram43210/Java/tree/master/BasicJava/ThreadDemo_sleep_App

Bitbucket Link:
https://bitbucket.org/ramram43210/java/src/8227d2165e265b2a41b3dbc1ecd1f352fea3b3f5/BasicJava/ThreadDemo_sleep_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