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) |
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()); } }
Before sleep of = DisplayThread-1 Before sleep of = DisplayThread-2 After sleep of = DisplayThread-2 After sleep of = DisplayThread-1
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:
No comments:
Post a Comment