DynamicTp Documentation

repository·master·Indexed 26 days ago

https://github.com/dromara/dynamic-tp

A lightweight, dynamic thread pool management framework for Java that extends ThreadPoolExecutor. It enables runtime parameter tuning via configuration centers (such as Nacos, Apollo, and Zookeeper), provides real-time monitoring with 20+ metrics, and supports alerting via WeCom, DingTalk, Feishu, and Email. Features include support for standard JUC and Spring ThreadPoolTaskExecutor, task enhancement via TaskWrapper, and integration with middleware like Tomcat, Jetty, Dubbo, RocketMQ, and gRPC.

Tokens
1.2K
Snippets
0
Records
9
Agent score
39%

What's inside DynamicTp

  1. Overview of DynamicTp Features

    master

    DynamicTp is a lightweight dynamic thread pool library that extends ThreadPoolExecutor to provide:

    • Runtime Parameter Modification: Adjust core/max pool size, keep-alive time, etc., without redeployment.
    • Monitoring & Alerting: Real-time status monitoring (20+ metrics) and notifications for config changes, thread activity, queue capacity, and rejections via WeCom, DingTalk, Feishu, Email, etc.
    • Task Enhancement: Implement TaskWrapper for context propagation (e.g., MDC, TTL, OpenTelemetry).
    • Middleware Management: Integrated support for Tomcat, Jetty, Dubbo, RocketMQ, gRPC, and more.
    • Extensibility: SPI-based architecture for custom configuration centers, alerting, metrics, and task wrapping.
  2. Overview of DynamicTp

    master
    DynamicTp is a lightweight, dynamic thread pool framework based on configuration centers. It provides real-time parameter adjustment, built-in monitoring and alerting, and management for common third-party middleware thread pools. It is designed to be zero-intrusive to business logic by leveraging Spring and configuration centers (like Nacos or Apollo) to manage thread pool lifecycles and configurations.
  3. Quick Start with DynamicTp

    master

    To integrate DynamicTp into your application, follow these four steps:

    1. Add the dependency: Include the dependency for your chosen configuration center (e.g., Nacos, Apollo, Zookeeper, etc.).
    2. Configure thread pools: Define your thread pool instances within your configuration center.
    3. Enable DynamicTp: Add the @EnableDynamicTp annotation to your main application class.
    4. Inject the executor: Use @Resource or @Autowired to inject the thread pool, or retrieve it manually using DtpRegistry.getExecutor("name").
  4. Quick Start: Integrate DynamicTp into your project

    master

    You can integrate DynamicTp into your Spring-based application in 4 simple steps:

    1. Add Dependencies: Include the dependency for your chosen configuration center (e.g., Nacos, Apollo, etc.).
    2. Configure Thread Pools: Define your thread pool instances in your configuration center using the required configuration format.
    3. Enable DynamicTp: Add the @EnableDynamicTp annotation to your Spring Boot main application class.
    4. Inject and Use: Use @Resource or @Autowired to inject the thread pool, or retrieve it via DtpRegistry.getExecutor("name").

    For more detailed configuration schemas, refer to the official documentation at https://dynamictp.cn.

  5. Configure Notification and Alerting

    master

    DynamicTp can trigger real-time alerts based on configured thresholds. Supported alert dimensions include:

    • Configuration Changes: Notifies when thread pool parameters are modified.
    • Liveness (Activity) Alarms: Alerts when the thread pool is not functioning correctly.
    • Queue Capacity Threshold Alarms: Alerts when the task queue reaches a certain limit.
    • Rejection Alarms: Alerts when the rejection policy is triggered.
    • Task Timeout Alarms: Alerts when tasks exceed execution or waiting time thresholds.

    Supported notification channels include WeChat Work (企微), DingTalk (钉钉), Feishu (飞书), Email, and Yunzhijia (云之家). Custom notification logic can be implemented via SPI.

  6. Configure Monitoring Collection Modes

    master

    DynamicTp supports four metric collection modes. You can specify which modes to use via the collectorTypes configuration key. The default mode is Micrometer.

    Available modes:

    • Logging: Outputs metrics as JSON to a dedicated log file.
    • Internal_logging: Outputs metrics as JSON to the application log.
    • Micrometer: Uses the Micrometer facade to collect metrics for platforms like Prometheus or InfluxDB.
    • Endpoint: Exposes a Spring Boot Endpoint for real-time metric retrieval via HTTP.
  7. Configure Monitoring Data Collection Types

    master

    DynamicTp supports four types of monitoring data collection via the collectorTypes attribute. You can configure which type to use based on your observability stack:

    • Logging: Outputs thread pool metrics in JSON format to a specified log file.
    • Internal_logging: Outputs thread pool metrics in JSON format to the project's standard log files.
    • Micrometer: Uses the Micrometer facade to collect metrics and export them to platforms like Prometheus or InfluxDB (requires Micrometer dependencies).
    • Endpoint: Exposes an endpoint to retrieve the latest metrics via HTTP requests.

    By default, Micrometer is used.

  8. Available Thread Pool Modes

    master

    DynamicTp provides several specialized executor types to suit different business scenarios:

    • DtpExecutor: The standard enhanced thread pool.
    • EagerDtpExecutor: Optimized for IO-intensive scenarios.
    • ScheduledDtpExecutor: For scheduled task execution.
    • OrderedDtpExecutor: For scenarios requiring task ordering.