Java Clean Architecture Masterclass

Java Clean Architecture Masterclass28-29 May

Join

logo

A lightweight dynamic thread pool based on configuration centers, with built-in monitoring & alerting, middleware thread pool management, and SPI extensibility

star

🌐 δΈ­ζ–‡ | 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)
// --- 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<Runnable> 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:


Features

Based on the above analysis, we extended ThreadPoolExecutor with the following goals:

  1. Dynamic parameter modification at runtime, taking effect instantly.

  2. Real-time monitoring of thread pool status with alerting, pushing notifications to office platforms.

  3. Periodic metric collection, integrated with visualization platforms like Grafana for dashboards.

  4. Thread pool management for commonly used third-party middleware.

Latest version features: βœ…


Architecture

The framework is divided into the following modules:

  1. Configuration change listener

  2. Thread pool management

  3. Monitoring

  4. Notification & alerting

  5. Third-party middleware thread pool management

Architecture

See the official documentation for details: Architecture


Quick Start

  1. Add the dependency for your configuration center (see official docs).

  2. Configure thread pool instances in your configuration center (see official docs).

  3. Add @EnableDynamicTp annotation to your application class.

  4. Inject via @Resource / @Autowired, or retrieve with DtpRegistry.getExecutor("name").

For detailed examples, see the example module and the official documentation.


Alerting

Alert Config Change Notification

Monitoring

Monitoring Data 1 Monitoring Data 2 Monitoring Data 3

Four metric collection modes are available, configured via collectorTypes (default: Micrometer):

  1. Logging: Metrics output as JSON to a dedicated log file.

  2. Internal_logging: Metrics output as JSON to the application log.

  3. Micrometer: Uses the Micrometer facade to collect metrics into storage platforms (Prometheus, InfluxDB, etc.).

  4. Endpoint: Exposes a Spring Boot Endpoint for real-time metric retrieval via HTTP.

πŸ“– See the official documentation for details: Alerting | Monitoring


Star History

Star History Chart


Repository


Contact

If you find this project helpful, please give us a star β€” your support drives us forward!

For questions, ideas, or suggestions, join our community to chat with 1700+ members.

Follow the WeChat public account and add my personal WeChat (note: dynamic-tp) to join the group.

To help the project grow, please register here: User Registration


Sponsors


Join libs.tech

...and unlock some superpowers

GitHub

We won't share your data with anyone else.