# threadpool-manager
**Repository Path**: battle__fortress/thread-pool-manager
## Basic Information
- **Project Name**: threadpool-manager
- **Description**: No description available
- **Primary Language**: Java
- **License**: Apache-2.0
- **Default Branch**: dev
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 3
- **Forks**: 0
- **Created**: 2021-10-21
- **Last Updated**: 2022-01-17
## Categories & Tags
**Categories**: Uncategorized
**Tags**: threadpool
## README
# 👑 Thread Pool Manager(TPM)
🍬Make multithreading easier.
## 一、项目介绍📚
随着计算机行业的飞速发展,摩尔定律逐渐失效,多核CPU成为主流。使用多线程并行计算逐渐成为开发人员提升服务器性能的基本武器。
J.U.C提供的线程池:ThreadPoolExecutor类,帮助开发人员管理线程并方便地执行并行任务。了解并合理使用线程池,是一个开发人员必修的基本功。
但是在实际开发过程中,线程池的运行状态对我们而言是透明的,我们无法观测线程池在执行过程中的诸多细节,并且根据业务场景的不同,线程池的运行状态也会存在波动,在生产环境中,当我们的线程池出现问题,如果我们不及时感知,并且做出相应调整,故障也在所难免。
针对以上线程池的透明性、波动性、及时性的问题,Thread Pool Manager (后面简称TPM),致力于让线程池具备:
1、可视化:对于线程池内部任务执行状态以及线程池运行参数实时监控;
2、实时监控:对线程池的异常状态进行监控,当运行状态出现异常时能够及时预警;
3、动态化:无需重启服务,对线上线程池参数进行动态调整。
## 二、包含组件🛠️
| 模块 | 模块名称 | 简介 |
| --------------------------------------------- | ------------- | --------------------------------------------------- |
| client-application-example | 客户端样板 | 如果你想知道怎么使用TPM,可以看看它 |
| thread-pool-manager-spring-boot-starter | 客户端starter | 客户端引入 |
| thread-pool-manager-spring-boot-autoconfigure | 自动配置 | - |
| thread-pool-manager-client | 客户端依赖 | 客户端核心源码 |
| thread-pool-manager-common | 公共配置 | - |
| thread-pool-manager-server | 服务端 | 包括Controller以及服务端启动器 |
| thread-pool-manager-cluster | 集群模块 | 包括集群寻址策略及通信方案等 |
| thread-pool-manager-config | 配置模块 | 包括线程池配置获取、刷新及长轮询处理等 |
| thread-pool-manager-http | 通信模块 | 基于Http的通信组件 |
| server-dependence | 服务端依赖 | 包括服务端事件监听机制及Result、Exception等基础设施 |
| thread-pool-manager-repository | 仓库 | 主要用于与MySQL对接 |
## 三、功能介绍📝
**功能总览**

## 四、使用方法🍐
1、将代码拉到本地,默认是集群模式启动,需要在`user.home`的`\tpm\conf\`目录下添加`cluster.conf`文件,配置集群信息。如果是单机模式启动,则添加启动参数`VM options:-Dtpm.standalone=true`;

2、启动 `thread-pool-manager-server` 项目;
3、启动样板项目`client-application-example`。
👉Postman请求服务端刷新线程池配置:路径 POST:http://localhost:3180/tpm/v1/configs
body请求体:namespace、projectId、threadPoolId参数用于定位线程池
```json
{
"namespace": "common",
"projectId": "message-center",
"threadPoolId": "consumer-thread-pool",
"corePoolSize": 17,
"maxPoolSize": 30,
"keepAliveTime": 15,
"rejectedType": 2,
"isAlert": 1,
"capacityAlert": 81,
"livenessAlert": 82
}
```
客户端控制台打印如下日志,客户端配置刷新成功
```
>>> [😊 Thread pool refresh] threadPoolId :: [CONSUMER-THREAD-POOL] coreSize :: [17=>27], maxSize :: [30=>30], queueType :: [2=>2], capacity :: [100=>100], keepAliveTime :: [15=>15], rejectedType :: [2=>2], isAlert :: [true=>true], capacityAlert :: [81=>81], livenessAlert :: [82=>82]
```
## 五、参考项目🎁
1、[Nacos](https://github.com/alibaba/nacos): an easy-to-use dynamic service discovery, configuration and service management platform for building cloud native applications.
2、[Hutool](https://github.com/dromara/hutool): A set of tools that keep Java sweet.