0

I'd like to know if there is a way to delay code execution in java. If there is, kindly post a reply and please note that I'm not referring to java android here

Similar to system c where i can write something like:

delay_ms(1000);

to delay the code from execution for a minute

Stephen
  • 29
  • 1

3 Answers3

5

You can use:

Thread.sleep(1000);

This causes the current Thread to sleep for 1000 milliseconds.

JetStream
  • 809
  • 1
  • 8
  • 28
0

Quoting https://docs.oracle.com/javase/tutorial/essential/concurrency/sleep.html

Thread.sleep causes the current thread to suspend execution for a specified period. This is an efficient means of making processor time available to the other threads of an application or other applications that might be running on a computer system.

k1eran
  • 4,492
  • 8
  • 50
  • 73
0

You can use Thread.sleep(1000) here.

Ruchira Gayan Ranaweera
  • 34,993
  • 17
  • 75
  • 115