简体   繁体   中英

thread blocking in fixed threadpool

I have two doubts:

  1. Regarding fixed threadpool in Java. Assume I created a fixed threadpool with 5 threads and all threads are currently executing, and also assume there are 4 task waiting in the queue to finish the execution of these threads. If all currently executing tasks got blocked what will happen? Whether there is a way to take task from that queue and put the blocked task in queue?

  2. How we will come to know whether a task is blocked or executing?

If all currently executing tasks got blocked what will happen? Whether there is a way to take task from that queue and put the blocked task in queue?

No, there's no facility for this. If a task begins executing and is blocked, then will block that thread until it completes normally, or is interrupted by a thread pool shutdown.

How we will come to know whether a task is blocked or executing?

If you need to know this, then you need to put some knowledge into the task code itself, which can then be queried by some other part of your application. Obviously, something else will need to keep hold of a reference to the task to allow this to work, before submitting it to the executor.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM