Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java multithreading: sleep and currentThread methods

I'm new to concurrent programming in Java. I've noticed that the methods sleep() and currentThread() of the Thread class are static. Since with a multi-core CPU, many threads can run at the same time, I was wondering how the thread is chosen between the ones in execution. Thank you.

like image 217
user3067088 Avatar asked Jun 21 '26 21:06

user3067088


1 Answers

That's easily found in the Javadocs for Thread:

For currentThread():

Returns a reference to the currently executing thread object.

For sleep():

Causes the currently executing thread to sleep

I.e. the Thread that calls the method for both methods.

like image 167
rgettman Avatar answered Jun 24 '26 09:06

rgettman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!