Page 1 of 1

python time.sleep(x) in java

Posted: Thu Sep 27, 2018 11:39 pm
by tony1812
Hello, in python, when I need to call a delay action, I can use time.sleep(x). What is it in Java?
Thread.sleep() ? Thanks.

Re: python time.sleep(x) in java

Posted: Fri Sep 28, 2018 12:24 am
by DougieLawson
Is your local Google broken (or is it comatose from celebrating too hard for it's 20th birthday)?

https://stackoverflow.com/questions/241 ... ay-in-java

Re: python time.sleep(x) in java

Posted: Fri Sep 28, 2018 10:21 am
by tony1812
Please don't give me the attitude. I did google it, I read the same post. but My little understanding is Thread.sleep() has something to do with a thread.. I am wondering if it can be applied to general purpose like time.sleep() in python.

I am not a genius like you. Java is brand new to me.

Re: python time.sleep(x) in java

Posted: Fri Sep 28, 2018 3:05 pm
by JosAH
tony1812 wrote:
Fri Sep 28, 2018 10:21 am
Please don't give me the attitude. I did google it, I read the same post. but My little understanding is Thread.sleep() has something to do with a thread.. I am wondering if it can be applied to general purpose like time.sleep() in python.

I am not a genius like you. Java is brand new to me.
The sleep() method in the Thread class is a static method and has nothing to do with any Thread in particular; you can use it and it makes your curent fall to sleep. The method can be interrupted (not very likely) but you have to embed it in a try ... catch block.

kind regards,

Jos