dromara /dynamic-tp
A lightweight dynamic thread pool framework with built-in monitoring and alerting, unified third-party thread pool management, and support for popular configuration centers (Nacos, Apollo, Zookeeper, Consul, and Etcd), extensible via SPI。
★ 4,813⑂ 861👁 52⑃ 298● 288▤ 19
More from this author
+0
Daily
+0
Weekly
-2
Monthly
4,813
stars
861
forks
52
watchers
298
prs
288
issues
19
releases
README
A lightweight dynamic thread pool based on configuration centers, with built-in monitoring & alerting, middleware thread pool management, and SPI extensibility
🌐 中文 | English
Website: https://dynamictp.cn 🔥
---
Pain Points
Have you encountered these issues when using ThreadPoolExecutor?
1. You created a ThreadPoolExecutor, but have no idea what values to set for the core parameters.
2. You set parameters based on experience, only to find after deployment that they need adjustment — requiring code changes and redeployment.
3. Thread pools are a black box to developers. You can't monitor their behavior until something breaks.
If so, DynamicTp may be the solution.
ThreadPoolExecutor provides set/get methods and extension points for its core parameters, enabling runtime dynamic modification.
👉 ThreadPoolExecutor dynamic methods (click to expand)
java
// --- Set ---
public void setCorePoolSize(int corePoolSize); // core pool size
public void setMaximumPoolSize(int maximumPoolSize); // max pool size
public void setKeepAliveTime(long time, TimeUnit unit); // thread idle keep-alive time
public void setThreadFactory(ThreadFactory threadFactory); // thread factory
public void setRejectedExecutionHandler(RejectedExecutionHandler handler); // rejection policy
public void allowCoreThreadTimeOut(boolean value); // allow core threads to time out
// --- Get ---
public int getCorePoolSize();
public int getMaximumPoolSize();
public long getKeepAliveTime(TimeUnit unit);
public BlockingQueue getQueue(); // task queue
public RejectedExecutionHandler getRejectedExecutionHandler();
public boolean allowsCoreThreadTimeOut();
// --- Extension hooks ---
protected void beforeExecute(Thread t, Runnable r); // before task execution
protected void afterExecute(Runnable r, Throwable t); // after task execution
Most modern internet projects adopt microservice architecture with a service governance stack. The distributed configuration center plays a key role — enabling real-time configuration changes with instant effect.
So, can we combine a configuration center to dynamically adjust thread pool parameters at runtime?
Absolutely. Configuration centers are highly available, relieving concerns about config push failures and reducing the effort of building a dynamic thread pool solution from scratch.
Background summary:
- Ubiquity: Thread pools are a fundamental tool used by 90%+ of Java developers to improve system performance.
- Uncertainty: Projects often contain many thread pools — some IO-intensive, some CPU-intensive — and optimal core parameters are hard to determine upfront, requiring runtime tuning.
- Lack of visibility: Thread pool metrics are invisible during operation. A monitoring & alerting mechanism is needed to detect issues before and during incidents.
- High availability: Configuration chang