Wait function in Java

后端 未结 6 863
梦谈多话
梦谈多话 2020-12-11 08:19

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 no

6条回答
  •  庸人自扰
    2020-12-11 08:45

    There's a simpler ( But possibly not better ) way to sleep that I have been using:

    public static void sleep(int amt) // In milliseconds
    {
        long a = System.currentTimeMillis();
        long b = System.currentTimeMillis();
        while ((b - a) <= amt)
        {
            b = System.currentTimeMillis();
        }
    }
    

    This will essentially cause everything your program is doing to cease until the time runs out. It also can cause a bit of lag. You have been warned.

提交回复
热议问题