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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With