Blocking a stream in a fixed stream

I have two doubts:

  • Regarding fixed threadpool in Java. Suppose I created a fixed threadpool with 5 threads and all threads are currently running, and also assume that 4 tasks have been completed in the queue to complete these threads. If all currently running tasks are blocked, what will happen? Is there a way to take a task from this queue and queue a locked task?

  • How do we know if a task is blocked or completed?

+4
source share
1 answer

If all currently running tasks are blocked, what will happen? Is there a way to take a task from this queue and queue a locked task?

No, there are no funds for this. If the task starts and is blocked, it will block this thread until it finishes normally or is interrupted by the completion of the thread pool.

How do we know if a task is blocked or completed?

If you need to know this, you need to introduce some knowledge into the task code, which can then be requested by another part of your application. Obviously, something else will need to keep a link to the task for this to work before sending it to the performer.

+1
source

Source: https://habr.com/ru/post/1381878/


All Articles