Diana
Thread.sleep
2 Answer(s)      4 years ago
Posted in : Java Beginners

View Answers

May 12, 2009 at 10:10 AM


The sleep() method of the thread is a static method. Calling sleep() causes the currently executing thread to sleep (temporarily cease execution) for the specified number of milliseconds. This means when you are calling t1.sleep() or t2.sleep(), you are causing the CURRENT thread to sleep.

May 12, 2009 at 1:38 PM


Hi Friend,

Thread.sleep() causes the current thread to suspend execution for a specified period.Here you allow the threads t1 and t2 to sleep.As t1 sleeps for 4 seconds and t2 7 seconds.Therefore, t1 finished first.

Thanks









Related Pages:
Thread.sleep timing
Thread.sleep timing  On what does the thread.sleep() time actually depend
Thread.sleep - Java Beginners
Thread.sleep  If I code Class Runner implements Runnable { Thread t1 = new Thread(this); Thread t2 = new Thread(this); Runner() { t1.start... the CURRENT thread to sleep.  Hi Friend, Thread.sleep() causes
Jdbc connectivity by type 4 driver
"); System.out.println("connection established"); Thread.sleep(1000); Statement stmt... created successfully"); Thread.sleep(1000); String insertQuery="insert...); System.out.println("Records inserted successfully"); Thread.sleep(2000
try catch
{ Thread.sleep(1000); } catch(InterruptException e...); try { Thread.sleep(1000
multi threads - Java Beginners
"); threadA.start(); Thread.sleep(500); Thread threadB = new Thread(runnable, "ThreadB"); threadB.start(); Thread.sleep(500); Thread threadC = new Thread(runnable, "ThreadC"); threadC.start(); Thread.sleep(500); Thread threadD = new
Threads(suspend(),resume()) run time abnormal behaviour
//{ System.out.println(i++); // Thread.sleep(2000... { Thread.sleep(1000); } catch(InterruptedException e... { System.out.println("try enter"); Thread.sleep(10000
animation in applet - Applet
"); g.drawImage(i1,50,50,null); Thread.sleep(100); } catch(Exception e...<300) s2=s1+20; try { Thread.sleep(100); } catch(Exception e
java code to display in audio - Java Beginners
"); AudioClip clip = Applet.newAudioClip(url); clip.loop(); Thread.sleep(5000... = Applet.newAudioClip(file.toURL()); clip.play(); Thread.sleep(500
Threrad
() { public void run() { try{ Thread.sleep(300...{ Thread.sleep(700); System.out.println(st2); } catch(Exception ex
please eslain me the flow of execution of this program
{ sb.append(i+":"); Thread.sleep(100); System.out.println("appending"); }catch...; } public void run(){ try{ while(!prod.dataprodover) Thread.sleep(10
Thread
Runnable() { public void run() { try{ Thread.sleep(1000...{ Thread.sleep(1000); for(int i=11;i<=20;i++){ sum2+=i...() { try{ Thread.sleep(1000); for(int i=21;i<=30;i
SCJP Module-8 Question-8
Given a sample code: public class Test { public static void main(String[] args) throws Exception { System.out.println("inside main"); Thread.sleep(2000); System.out.println("thread sleep"); } } Which
Display message automatically using Java Swing
Thread.sleep(time)  pauses the execution for the specified number...; while(true){ try { Thread.sleep(time); JOptionPane.showMessageDialog
Pick random element from Set
. The for loop displays the random element five times and Thread.sleep() method...(); for (int i = 0; i < 5; i++) { Thread.sleep(5000
Java MultiThread - Java Beginners
); Thread.sleep(500); } } catch (InterruptedException e) { System.out.println... Thread:" + i); Thread.sleep(1000); } } catch (InterruptedException e
Please clarify my doubt
()"); /*try { //Thread.sleep(1000); } catch... + "entered B.bar()"); /*try { Thread.sleep(1000
Set delay time in JOptionPane
the Thread.sleep() method we have allowed the message to be displayed after...; ); if (str == null) return; try { Thread.sleep(time
plese expalin the flow of this program
){ System.out.println("bookticket locked on train"); try{ Thread.sleep...){ System.out.println("cancellticket locked on comp"); try{ Thread.sleep(200
please explain me the flow of this program
{ Thread.sleep(200);} catch(InterruptedException ie){} } System.out.println...){ System.out.println("cancellticket locked on train"); try{ Thread.sleep
sleep method in thread java program
(str[i]); Thread.sleep(5000); } catch... { System.out.println(str[i]); Thread.sleep(5000
Java Thread : sleep() method
. The Thread.sleep() method pauses the current thread for a specified time period... sleep() method..."); Thread.sleep(100, 100); } catch (Exception e
Java Thread Interrupted
..."); thread.start(); try { Thread.sleep(500...."); Thread.sleep(500); } catch (InterruptedException e
java Collections - Java Beginners
(set.size())]); Thread.sleep(5000); } } } Thanks
java - Java Beginners
()); Thread.sleep(1000
How do i slow down the game (othello game)??
the (thread.sleep) but it didn't solve the problem... can you help me please.. thank
Java Method Synchronized
. Thread.sleep ( ):This causes the currently executing thread to sleep (cease...;ThreadA"); threadA.start(); Thread.sleep(500);  Thread threadB ...(); Thread.sleep(500);  Thread threadC = new Thread(runnable, "
Interrupting a thread.
;  try {       Thread.sleep(40000...();     Thread.sleep(200);     ...;Thread.sleep(500);     th2.interrupt();   
notify and notifyAll methods - Java Beginners
(); Thread.sleep(500); Thread thread2 = new Thread(r1, "B"); thread2.start(); Thread.sleep(500); Thread thread3 = new Thread(r2, "C"); thread3.start(); Thread.sleep(1000); thread1.interrupt
hi again - Java Beginners
(this); t.start(); } public void run(){ try { Thread.sleep(10); System.out.println... in Code : Thread.sleep(1); import java.io. *; import java.util.*; class...(){ try { Thread.sleep(1); System.out.println(s1); float counter=0; float
Animation in Applets - Applet
(getDocumentBase(),"a1.gif"); g.drawImage(i1,50,50,null); Thread.sleep(100... { Thread.sleep(100); } catch(Exception e... { thread.sleep(10); } catch (Exception e
Java Program
{ Thread.sleep(5000); File inputFile = new File(f1...{ Thread.sleep(5000); File inputFile = new File(f2...); Thread.sleep(5000); File inputFile = new File(f3
Splash Screen in Java Swing
, 100); window.setVisible(true); try { Thread.sleep(5000); } catch
Java Sleep Thread
) { try { Thread.sleep(1000); System.out.println("Thread
java multithread - Java Beginners
Thread.sleep(900000); } catch (Exception e
creating multiple threads - Java Beginners
= new Stack(); Thread.sleep(1000); System.out.print ("Push
Threads on runnable interface - Java Beginners
:"+Thread.currentThread().getName()); try{ Thread.sleep(1000); }catch(Exception
Threads on runnable interface - Java Beginners
("Thread Name :"+Thread.currentThread().getName()); try{ Thread.sleep
java swings - Java Beginners
" ); if (str == null) return; try { Thread.sleep(time
java multithread - Java Beginners
:" +Thread.currentThread().getName()); try{ Thread.sleep(1000); }catch
time
); while(true){ try { Thread.sleep(1000); Calendar cal = new
date and time in awt(java)
(); setVisible(true); while(true){ try { Thread.sleep(1000
Count the character in java
{ Thread.sleep(5000); String st=str.replaceAll(" ", ""); char ch
java program
++ ){ System.out.println(str+ " : "+ i); try{ Thread.sleep(1000
JProgressBar
() { while (num < 1000) { jpb.setValue(num); try{ Thread.sleep(500
Java Thread destroy
()+")"); } } @Override public void run() { try { Thread.sleep(500); } catch
Count Active Thread in JAVA
void run() { try { Thread.sleep(500); } catch (InterruptedException
help again plz sorry - Java Beginners
; t=new Thread(this); t.start(); } public void run(){ try { Thread.sleep..., Please change some code, public void run(){ try{ Thread.sleep(10
how to control program/thread 's access authority - Security
{ Thread.sleep(1000); } catch(Exception e){} vec.addElement(s...(); try{ Thread.sleep(500); } catch
Comparing two Dates in Java with the use of after method
we have defined firstDate object and then we used the Thread.Sleep(1000) method...;new Date();   try{   Thread.sleep(1000);   }catch
Comparing two Dates in Java with the use of before method
the Thread.Sleep(1000) method to add a delay of 1 second. After 1 second delay our example...;new Date();   try{   Thread.sleep(1000);   }catch

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.