gitmyhub

dynamic-tp

Java ★ 4.8k updated 1d ago

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。

A Java library that lets you change thread pool settings while your app is running, with no restarts needed. It also adds monitoring, alerts, and visibility into pools inside Tomcat, Dubbo, RocketMQ, and other frameworks you're already using.

JavaSpring BootPrometheusNacosApollosetup: moderatecomplexity 3/5

DynamicTp is a Java library that solves a common headache with thread pools: you set the configuration at startup, it goes live, and then you discover the numbers were wrong. Changing them normally means editing code, redeploying, and restarting the service. DynamicTp lets you adjust thread pool settings while the application is running, without any downtime or redeployment.

A thread pool, in this context, is how Java applications handle many tasks at once. You configure it with parameters like how many threads to keep active at minimum, how many to allow at peak, and how large the waiting queue can grow. Getting these numbers right matters for performance, but the right values often only become clear once the application is actually handling real traffic. DynamicTp stores these settings in a configuration center (it supports Nacos, Apollo, Zookeeper, Consul, Etcd, and others), so that pushing a change to the config center immediately updates the running thread pool with no restart needed.

Beyond dynamic adjustment, the library adds monitoring and alerting. It collects over 20 metrics covering thread activity, queue depth, task throughput, and response time percentiles. These can be exported to Prometheus, logged as JSON, or queried via a Spring Boot endpoint. Alert rules let teams receive notifications when a thread pool hits capacity, starts rejecting tasks, or tasks begin taking too long. Alerts can be delivered via DingTalk, WeChat Work, Feishu, email, or a custom channel.

The library also reaches into third-party components that manage their own internal thread pools, including Tomcat, Dubbo, RocketMQ, gRPC, RabbitMQ, and about a dozen others. Teams using those frameworks gain the same dynamic tuning and monitoring for pools they previously had no visibility into.

Setup is described as four steps: add the dependency, configure the thread pool in the config center, annotate the application startup class, and inject the pool for use. Existing standard Java thread pools and Spring task executors can be brought under management by adding a single annotation.

Where it fits