ThreadPoolExecutor and Pool Sizes Quirk
I recently ran into a problem while using ThreadPoolExecutor. As you probably know, ThreadPoolExecutor takes (among the others), two parameters - corePoolSize and maximumPoolSize. Also by default (and in Java5 you can't change the default) it never stops threads from the "core" pool.
So I've tried to set corePoolSize quite low and raise maximumPoolSize. After some checks I could see that my pool does not behave as expected - I've got very long queue and only core pool threads started. After going deeper into the documentation I've found this:
If there are more than corePoolSize but less than maximumPoolSize threads running, a new thread will be created only if the queue is full.And I've used unbounded queue. So, basically, with unbounded queue one should never make maximumPoolSize larger then corePoolSize (at least this won't make any impact - no more then core pool threads will be created).
(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)