4
Is it possible to delay in Java? Like for example, I have two messages and I want the second one to appear just a few seconds later,?
4
Is it possible to delay in Java? Like for example, I have two messages and I want the second one to appear just a few seconds later,?
3
Try using Thread.Sleep();
package com.journaldev.threads;
public class ThreadSleep {
public static void main(String[] args) throws InterruptedException {
long start = System.currentTimeMillis();
// pausa de 2 segundos
Thread.sleep(2000);
System.out.println("Sleep time in ms = "+(System.currentTimeMillis()-start));
}
}
Browser other questions tagged java delay
You are not signed in. Login or sign up in order to post.
Beyond the
Thread.sleep()
it is possible to use theenum
java.uti.concurrent.TimeUnit
, it increases the readability of the code, for example a delay of 5 minutes withThread.sleep()
staysThread.sleep(300000)
, already withTimeUnit
staysTimeUnit.MINUTES.sleep(5)
– NinjaTroll