Answers for "java wait"

0

java pause

//deprecated in main thread:
try {
  Thread.sleep(1000);//time is in ms (1000 ms = 1 second)
} catch (InterruptedException e) {e.printStackTrace();}

//please use bellow instead:
Timer timer = new Timer();
timer.schedule(new TimerTask() {
  @Override
  public void run() {
    //what you want to do
  }
}, 1000);//wait 1000ms before doing the action
Posted by: Guest on July-07-2020
0

java wait

// Sleep 1 second
TimeUnit.SECONDS.sleep(1);
// Sleep 1 minute
TimeUnit.MINUTES.sleep(1);
Posted by: Guest on September-30-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
2

wait method in java

java.lang.Object.wait() causes current thread to wait until another thread 
invokes the notify() method or the notifyAll() method for this object.
Posted by: Guest on July-09-2020

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language