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
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
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
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