Answers for "java wait for seconds"

2

java utils wait for seconds

try        
{
    Thread.sleep(1000);
} 
catch(InterruptedException ex) 
{
    Thread.currentThread().interrupt();
}
Posted by: Guest on November-18-2020
6

java delay

Syntax :
=========================================================
	Thread.sleep(1000); // 1000 milliseconds..          |
=========================================================
int i=0;
for(;;){
	Thread.sleep(2000); // set time delay to 2 seconds.. 
  	System.out.println(i++); // output : every output will display after 2 seconds..   	
}
Posted by: Guest on May-19-2020
0

java wait 2 seconds

/** from: java.util.concurrent.TimeUnit **/

// Sleep for 1 second
TimeUnit.SECONDS.sleep(1);

// Sleep for 1 minute
TimeUnit.MINUTES.sleep(1);
Posted by: Guest on July-03-2021
0

java wait a second

// Java program to demonstrate 
// sleep() method of TimeUnit Class 
  
import java.util.concurrent.*; 
  
class WaitASecond { 
    public static void main(String args[]) 
    { 
        // Get time to sleep 
        long timeToSleep = 0L; 
  
        // Create a TimeUnit object 
        TimeUnit time = TimeUnit.SECONDS; 
  
        try { 
  
            System.out.println("Going to sleep for "
                               + timeToSleep 
                               + " seconds"); 
  
            // using sleep() method 
            time.sleep(timeToSleep); 
  
            System.out.println("Slept for "
                               + timeToSleep 
                               + " seconds"); 
        } 
  
        catch (InterruptedException e) { 
            System.out.println("Interrupted "
                               + "while Sleeping"); 
        } 
    } 
}
Posted by: Guest on November-22-2020

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language