开发者

Java Executor Service Thread Pool [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 10 years ago.

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 开发者_JAVA百科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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜