Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wait function in Java

Tags:

java

So I am writing a Java code to represent a heap sort and to represent the operation I need to have a waiting function which will wait between different operation but I am not sure if there is a function in Java that does that or do I need to write the function by myself and how would i do that.

Representing heap sport is a homework but writing the waiting function isn't so I appreciate your help

like image 983
user220755 Avatar asked Nov 27 '22 19:11

user220755


2 Answers

You're looking for Thread.sleep(int milliseconds)

like image 189
SLaks Avatar answered Dec 05 '22 11:12

SLaks


Thread.sleep() is what you are looking for.

The exception it throws will likely puzzle you if you are a Java newbie. Most likely you will want to propagate it up or discard it and reset the interrupt flag using Thread.currentThread().interrupt()

like image 32
Christopher Oezbek Avatar answered Dec 05 '22 09:12

Christopher Oezbek