Java Executor Service Message Pool

If I create a pool of fixed-sized threads with 10 threads in java using the Executor framework:

private final ExecutorService pool; pool = Executors.newFixedThreadPool(10); 

and then try to submit more than 10 tasks (for example, 12 tasks);

 for (int i = 0 ; i < 12 ; i++) { pool.execute(new Handler(myRunnable)); } 

What will happen to the additional tasks (additional two tasks, as an example of 12 tasks)? Will they be blocked until the thread completes its work?

+4
source share
1 answer

Javadoc citation for Executors.newFixedThreadPool(int nThreads) (emphasis mine):

Creates a thread pool that reuses a fixed number of threads working with a common unlimited queue. At any time, in most cases, nThreads will be active processing tasks. If additional tasks are transferred when all threads are active, they will wait in a queue until a thread is available . If any thread terminates due to a run-time failure before shutting down, a new one will take its place, if necessary, for subsequent tasks. Threads in the pool will exist until they are explicitly disabled.

Javadocs for code as mature as the Java Concurrency Framework contain a lot of knowledge. Keep them close.

+22
source

All Articles