跪拜 Guibai
← All articles
Backend · Frontend · Artificial Intelligence

Default SpringBoot Thread Pool Fails at 3,000 QPS; Custom Executor Handles 4,500

By 阿橙的百宝箱 ·
Read original on juejin.cn ↗ Google Translate ↗ Alt translation

A misconfigured thread pool can turn a promotional spike into a service outage; the before-and-after numbers show the fix is specific and measurable. Engineering teams running SpringBoot in production should treat the default async executor as a liability and apply the same bounded-queue, rejection-policy, and metric checks.

Summary

SpringBoot applications that rely on the default async executor will discover the hard way that it was never designed for high concurrency. The default `SimpleAsyncTaskExecutor` creates a fresh thread for every request, with no queue and no thread reuse. At a QPS of 3,000, that strategy turns a normal 50ms response into a 5-second timeout and floods logs with `RejectedExecutionException`. The root cause isn't hardware or JVM tuning; it's a configuration default that assumes low-volume, short-lived tasks.

Replacing the default with an explicitly sized `ThreadPoolTaskExecutor` changes the picture dramatically. Setting core pool to 20, max to 100, and a bounded queue of 200 gives burst traffic somewhere to wait instead of instantly failing. The performance data is stark: default config tops out at 800 QPS with a 15% error rate and 1.2s average latency; the custom pool handles 4,500 QPS at 65ms with a 0.1% error rate. The article also walks through five operational details that separate a functioning pool from a reliable one: bounded queues over unbounded ones, `CallerRunsPolicy` instead of `AbortPolicy`, core thread timeout handling, manual propagation of logging MDC context, and Micrometer monitoring for queue capacity and active count.

No framework will ever supply a thread pool that fits every traffic pattern. The point is that defaults prioritize universality over performance, and any service expecting traffic spikes must explicitly configure and monitor its executors. Reading the article is a reminder that a single `@Async` annotation is not a concurrency strategy.

Takeaways
— SpringBoot's @Async and WebMvc share a single SimpleAsyncTaskExecutor by default, which creates a new thread per request.
— The default configuration produces RejectedExecutionException and 5-second response times when QPS exceeds 3,000.
— A ThreadPoolTaskExecutor with corePoolSize 20, maxPoolSize 100, and queueCapacity 200 raised QPS capability from 800 to 4,500.
— ArrayBlockingQueue is recommended over the unbounded LinkedBlockingQueue to avoid memory exhaustion.
— For high concurrency, CallerRunsPolicy is suggested over the default AbortPolicy to let the calling thread execute rejected tasks.
— Setting allowCoreThreadTimeOut(true) releases idle threads, but core size should remain large enough to avoid frequent creation/destruction.
— Async threads lose MDC logging IDs; pass them manually with TaskDecorator.
— Micrometer metrics like queue.remaining.capacity and active.count are critical to monitor pool health.
Conclusions

Simplistic framework defaults trade throughput for generality; they become active liabilities only after load dynamics change, which is why the QPS table is so convincing.

The recommendation to use CallerRunsPolicy is a backpressure trade-off, not a universal win: it avoids dropping tasks but can slow the caller thread, which may be acceptable for some workloads.

Concepts & terms
SimpleAsyncTaskExecutor
SpringBoot's default executor that creates a new thread per task, with no thread reuse or queueing.
ThreadPoolTaskExecutor
A configurable executor from Spring that supports core/max pool sizes, a work queue, and rejection policies.
CallerRunsPolicy
A rejection strategy that runs the rejected task in the thread that submitted it, preventing task loss at the cost of caller blocking.
MDC (Mapped Diagnostic Context)
A logging context for tracking request IDs across threads; must be manually propagated to async threads.
Micrometer
Spring Boot's metrics instrumentation library; here used to expose thread pool queue capacity and active count.
Source: juejin.cn ↗ Google Translate ↗ Backup ↗