MediumExperience level: 3-5 years · 8-15 years1 min read

How do corePoolSize, maxPoolSize, the queue and rejection policy interact in ThreadPoolExecutor?

Reviewed by Gurusankar M.

Asked inAmazonGoogleDeloitte
#threadpoolexecutor#tuning#rejectedexecutionhandler#queue
Report issue

Short Answer

Tasks first fill core threads, THEN the queue, and only when the queue is full are threads grown to max — finally the RejectedExecutionHandler fires. A common surprise: with an unbounded queue, max is never reached because the queue never fills.

On this page

Concept Made Simple

Coffee Chat Question

“How do corePoolSize, maxPoolSize, the queue and rejection policy interact in ThreadPoolExecutor?”

Remember It Faster

Mind Map Answer

1. core threads
created up to corePoolSize
2. queue
tasks queued until full
3. max threads
grow core→max once queue full
4. reject
RejectedExecutionHandler

Learn by Doing

Hands-on Keyboard

java
new ThreadPoolExecutor(
    10, 50,                       // core, max
    60, TimeUnit.SECONDS,
    new ArrayBlockingQueue<>(1000), // BOUNDED
    new ThreadPoolExecutor.CallerRunsPolicy()); // backpressure

Think Beyond the Expected

What If?

You set maxPoolSize=100 but only ever see 10 threads under heavy load — why?

Because your queue is unbounded (or huge): the pool only grows past corePoolSize when the queue is FULL. With an unbounded queue the queue never fills, so threads never exceed core. Use a bounded queue to actually reach maxPoolSize.

Real World

The 'max threads never used' gotcha trips many teams; pairing a bounded queue with CallerRunsPolicy gives natural backpressure (the submitter runs the task) instead of unbounded growth.

Interviewer's Expectation

Keywords they're listening for:

  • core→queue→max ordering
  • unbounded queue defeats max
  • rejection handlers
  • CallerRunsPolicy backpressure
  • keepAlive

Common Mistakes

  • Expecting maxPoolSize to engage with an unbounded queue
  • Using AbortPolicy and not handling rejections
  • Oversized pools causing context-switch thrash

Best Practices

  • Use a bounded queue sized to your latency budget
  • Pick a rejection policy intentionally (often CallerRuns)
  • Monitor queue depth and active count

Follow-up Questions

  1. What do the four built-in rejection policies do?
  2. How does CallerRunsPolicy create backpressure?
  3. When would you allowCoreThreadTimeOut?

Continue Learning with AI

Take this question deeper with your favourite AI assistant. Pick a depth, copy the prompt, or open it directly — AI is your learning companion, not a shortcut.

Plain-language foundations

I'm preparing for a software engineering interview and want to understand this from scratch, as a beginner.

Topic: Threads & Pools (Multithreading)
Interview question: "How do corePoolSize, maxPoolSize, the queue and rejection policy interact in ThreadPoolExecutor?"

Please:
1. Explain the core idea in simple, plain language, using an everyday analogy.
2. Define any technical terms you use.
3. Walk through one small, concrete example.
4. Finish with a single sentence I can easily remember.

Keep the tone friendly and assume I'm new to this topic.
Open inChatGPTGeminiClaude

Was this answer helpful?

Affiliate links

Equipment for a comfortable, productive setup.

As an Amazon Associate I earn from qualifying purchases.