Topic disabled for thread scheduling purposes. What does it mean?

When I was going through the Javadoc for CountDownLatch I came across a line in the documentation for the wait method.

If the current counter is greater than zero, then the current thread is disconnected for thread scheduling purposes and is dormant

What does current thread becomes disabled for thread scheduling purposes

it mean here?

+3


source to share


2 answers


On a given system, only a fixed number of threads can actually run concurrently (you're limited by the number of cores in the machine.) When there are more threads to run than there are cores, the scheduler thread will cycle through the threads in some way, giving each one some CPU time.

However, in some cases, it doesn't make sense to specify the thread time on the CPU. For example, if a thread receives a reverse latch whose sum is greater than zero, then that thread will get stuck waiting for other threads to receive the latch as well. So there is no point in pointing out that the thread has any CPU time, since the thread just sits and waits for other threads. Therefore, typically, the scheduler does not even try to give the thread any CPU time, preferring instead to schedule other threads that may still be making progress. After all threads have received the countdown latch, all threads that have been blocked this way are then put back into the scheduler for further consideration.



In other words, the thread is terminated and the scheduler would be wise not to waste time trying to start it until the latch is ready.

Hope this helps!

+7


source


It simply means that the code in that thread will not progress further until latch.countDown () is called on the same latch from other threads, thus making the number of latches 0.



A thread is started when it is in the runnable state and the scheduler schedules it. When threads are disabled for scheduling, it won't get its fair share of CPU cycles, so it won't start, which means its program counter won't increment. His stack will stay where he was until he gets the CPU again.

0


source







All Articles