How do I make a delay in Java?

If you want to pause then use java.util.concurrent.TimeUnit: TimeUnit.SECONDS.sleep(1); To sleep for one second or TimeUnit.MINUTES.sleep(1); To sleep for a minute. As this is a loop, this presents an inherent problem – drift. Every time you run code and then sleep you will be drifting a little bit from running, say, every second. If this … Read more