How to suspend current thread for X seconds in java?

+1 vote
686 views
asked Nov 16, 2017 by Hitesh Garg (799 points)  

How to suspend a current Thread for X seconds lets say 10 seconds in Java?

1 Answer

+1 vote
answered May 23, 2018 by Hitesh Garg (799 points)  
 
Best answer

It can be easily done by the Thread.sleep method.

So the code below will put a thread to sleep for 50 seconds

try {
  Thread.sleep(50*1000);
} catch(InterruptedException e) { 
}
...