-7

How do I execute the Java code after a few minutes?

I want very simple code or function. How do I pause a line of code in Java?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131

1 Answers1

0

Use Thread.sleep(long mills);. This function takes a long value in milliseconds (thousandths of a second) to pause

Hope this helps!

Sam
  • 2,350
  • 1
  • 11
  • 22
  • package com.journaldev.threads; public class ThreadSleep { public static void main(String[] args) throws InterruptedException { long start = System.currentTimeMillis(); Thread.sleep(5000); } } is this right, can u still modify it. – Manoj Maharana Dec 07 '17 at 18:12
  • If you want your code to pause for 5 seconds, simply use `Thread.sleep(5000)` where you want it to pause. That's it. – Sam Dec 07 '17 at 18:14
  • For Example : Thread.sleep(1000) Here, 1000 = 1 second. it will wait for 1 second – Manoj Maharana Aug 22 '18 at 17:20