Logo

Programming-Idioms

  • Kotlin
  • Java

Idiom #45 Pause execution for 5 seconds

Sleep for 5 seconds in current thread, before proceeding with the next instructions.

The pedestrian walks, then stays still for 5 seconds, then resumes walking
Thread.sleep(5000);

Unit is millisecond
import java.util.concurrent.TimeUnit;
TimeUnit.SECONDS.sleep(5);

Java 7+
Thread.sleep(5000L)
delay 5.0;

New implementation...
< >
programming-idioms.org