1

whatever I set the size of pool, the run results seems to not exceed the pool size.For example:

 BlockingQueue<Runnable>  queue = new LinkedBlockingQueue<>();
 ThreadPoolExecutor executor = new ThreadPoolExecutor(8, 15, 1, TimeUnit.DAYS, queue);
 executor.execute(new Runnable() {
                public void run() {

                }
            });

when I set 8, the first 8 results will synchronize. But the following only run one by one.
what's wrong and how to fix?

WhiteBanana
  • 349
  • 4
  • 20

1 Answers1

2

Read the javadoc.

It says:

Queuing

Any BlockingQueue may be used to transfer and hold submitted tasks. The use of this queue interacts with pool sizing:

If fewer than corePoolSize threads are running, the Executor always prefers adding a new thread rather than queuing. If corePoolSize or more threads are running, the Executor always prefers queuing a request rather than adding a new thread. If a request cannot be queued, a new thread is created unless this would exceed maximumPoolSize, in which case, the task will be rejected.

[...]

Unbounded queues. Using an unbounded queue (for example a LinkedBlockingQueue without a predefined capacity) will cause new tasks to wait in the queue when all corePoolSize threads are busy. Thus, no more than corePoolSize threads will ever be created.

Community
  • 1
  • 1
JB Nizet
  • 678,734
  • 91
  • 1,224
  • 1,255
  • thank you:) I got it. So, I got this answer http://stackoverflow.com/questions/1435903/specifying-threadpoolexecutor-problem – WhiteBanana Nov 18 '15 at 08:15