Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

ThreadPoolExecutor and Pool Sizes Quirk

DZone's Guide to

ThreadPoolExecutor and Pool Sizes Quirk

· Java Zone
Free Resource

Make it happen: rapid app development on Kubernetes as a managed service.

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).

Tutorial: WordPress as distributed microservices on Kubernetes.

Topics:

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}