Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 205
nantitv Avatar asked Nov 18 '11 10:11

nantitv


1 Answers

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.

like image 165
skaffman Avatar answered Oct 04 '22 15:10

skaffman