If I create a fixed size thread pool with 10 threads in java using Executor framework:
private final ExecutorService pool;
pool = Executors.newFixedThreadPool(10);
and then try to submit more than 10 tasks (say for an example, 12 tasks);
for (int i = 0 ; i < 12 ; i++) {
pool.execute(new Handler(myRunnable));
}
What will happen to the extra tasks (extra two tasks as per the example of 12 tasks)? Will they be blocked until a thread has finished its work?
Quoting the Javadoc for Executors.newFixedThreadPool(int nThreads)
(emphasis mine):
Creates a thread pool that reuses a fixed number of threads operating off a shared unbounded queue. At any point, at most nThreads threads will be active processing tasks. If additional tasks are submitted when all threads are active, they will wait in the queue until a thread is available. If any thread terminates due to a failure during execution prior to shutdown, a new one will take its place if needed to execute subsequent tasks. The threads in the pool will exist until it is explicitly shutdown.
The Javadocs for code as mature as the Java Concurrency Framework contain a great wealth of knowledge. Keep them close.
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