Skip to content

Commit

Permalink
Release 1.5.0 Documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
magestacks committed Apr 15, 2023
1 parent e141e5d commit 5fc2906
Show file tree
Hide file tree
Showing 76 changed files with 3,606 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ sidebar_position: 5
<dependency>
<groupId>cn.hippo4j</groupId>
<artifactId>hippo4j-config-spring-boot-1x-starter</artifactId>
<version>1.4.3-upgrade</version>
<version>1.5.0</version>
</dependency>
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Nacos、Apollo、Zookeeper、ETCD、Polaris、Consul 配置中心任选其一。
<dependency>
<groupId>cn.hippo4j</groupId>
<artifactId>hippo4j-config-spring-boot-starter</artifactId>
<version>1.4.3-upgrade</version>
<version>1.5.0</version>
</dependency>
```

Expand Down Expand Up @@ -67,8 +67,8 @@ spring:
namespace: xxxx
# 配置中心文件格式
config-file-type: yml
# tomcat、undertow、jetty 三种容器线程池,任选其一
undertow:
# 支持 tomcat、undertow、jetty 三种容器线程池
web:
core-pool-size: 100
maximum-pool-size: 200
keep-alive-time: 1000
Expand Down
4 changes: 2 additions & 2 deletions docs/docs/user_docs/getting_started/hippo4j-adapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Hippo4j 目前已支持的三方框架线程池列表:
<artifactId>hippo4j-spring-boot-starter-adapter-spring-cloud-stream-rocketmq</artifactId>
<!-- SpringCloud Stream RabbitMQ -->
<artifactId>hippo4j-spring-boot-starter-adapter-spring-cloud-stream-rabbitmq</artifactId>
<version>1.4.3-upgrade</version>
<version>1.5.0</version>
</dependency>
```

Expand All @@ -43,7 +43,7 @@ Hippo4j 目前已支持的三方框架线程池列表:
<dependency>
<groupId>cn.hippo4j</groupId>
<artifactId>hippo4j-spring-boot-starter-adapter-all</artifactId>
<version>1.4.3-upgrade</version>
<version>1.5.0</version>
</dependency>
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ spring:
<dependency>
<groupId>cn.hippo4j</groupId>
<artifactId>hippo4j-spring-boot-starter-monitor-micrometer</artifactId>
<version>1.4.3-upgrade</version>
<version>1.5.0</version>
</dependency>
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ SpringBoot Pom 引入 Hippo4j Starter Jar。
<dependency>
<groupId>cn.hippo4j</groupId>
<artifactId>hippo4j-spring-boot-starter</artifactId>
<version>1.4.3-upgrade</version>
<version>1.5.0</version>
</dependency>
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ sidebar_position: 5
<dependency>
<groupId>cn.hippo4j</groupId>
<artifactId>hippo4j-config-spring-boot-1x-starter</artifactId>
<version>1.4.3-upgrade</version>
<version>1.5.0</version>
</dependency>
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Nacos、Apollo、Zookeeper、ETCD、Polaris、Consul 配置中心任选其一。
<dependency>
<groupId>cn.hippo4j</groupId>
<artifactId>hippo4j-config-spring-boot-starter</artifactId>
<version>1.4.3-upgrade</version>
<version>1.5.0</version>
</dependency>
```

Expand Down Expand Up @@ -67,8 +67,8 @@ spring:
namespace: xxxx
# 配置中心文件格式
config-file-type: yml
# tomcat、undertow、jetty 三种容器线程池,任选其一
undertow:
# 支持 tomcat、undertow、jetty 三种容器线程池
web:
core-pool-size: 100
maximum-pool-size: 200
keep-alive-time: 1000
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Hippo4j 目前已支持的三方框架线程池列表:
<artifactId>hippo4j-spring-boot-starter-adapter-spring-cloud-stream-rocketmq</artifactId>
<!-- SpringCloud Stream RabbitMQ -->
<artifactId>hippo4j-spring-boot-starter-adapter-spring-cloud-stream-rabbitmq</artifactId>
<version>1.4.3-upgrade</version>
<version>1.5.0</version>
</dependency>
```

Expand All @@ -43,7 +43,7 @@ Hippo4j 目前已支持的三方框架线程池列表:
<dependency>
<groupId>cn.hippo4j</groupId>
<artifactId>hippo4j-spring-boot-starter-adapter-all</artifactId>
<version>1.4.3-upgrade</version>
<version>1.5.0</version>
</dependency>
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ spring:
<dependency>
<groupId>cn.hippo4j</groupId>
<artifactId>hippo4j-spring-boot-starter-monitor-micrometer</artifactId>
<version>1.4.3-upgrade</version>
<version>1.5.0</version>
</dependency>
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ SpringBoot Pom 引入 Hippo4j Starter Jar。
<dependency>
<groupId>cn.hippo4j</groupId>
<artifactId>hippo4j-spring-boot-starter</artifactId>
<version>1.4.3-upgrade</version>
<version>1.5.0</version>
</dependency>
```

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"label": "开发者手册",
"position": 5,
"link": {
"type": "generated-index",
"description": "Hippo4j 留给使用者能够扩展的知识点。"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
---
sidebar_position: 1
---

# 拒绝策略自定义

Hippo4j 通过 SPI 的方式对拒绝策略进行扩展,可以让用户在 Hippo4j 中完成自定义拒绝策略实现。

## Hippo4j Server 拒绝策略扩展

自定义拒绝策略,实现 `CustomRejectedExecutionHandler` 接口,示例如下:

```java
public class ErrorLogRejectedExecutionHandler implements CustomRejectedExecutionHandler {

@Override
public Integer getType() {
return 12;
}

@Override
public RejectedExecutionHandler generateRejected() {
return new CustomErrorLogRejectedExecutionHandler();
}

public static class CustomErrorLogRejectedExecutionHandler implements RejectedExecutionHandler {

@Override
public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) {
Logger logger = LoggerFactory.getLogger(this.getClass());
logger.error("线程池抛出拒绝策略");
}
}
}
```

创建 `src/main/resources/META-INF/services` 目录,创建 SPI 自定义拒绝策略文件 `cn.hippo4j.common.executor.support.CustomRejectedExecutionHandler`

`cn.hippo4j.common.executor.support.CustomRejectedExecutionHandler` 文件内仅放一行自定义拒绝策略全限定名即可,示例:

```text
cn.hippo4j.example.core.handler.ErrorLogRejectedExecutionHandler
```

创建、修改线程池页面选择 `CustomRejectedPolicy(自定义 SPI 策略)`

![](https://images-machen.oss-cn-beijing.aliyuncs.com/image-20220813173907814.png)

拒绝策略触发时,完成上述代码效果,仅打印异常日志提示。

```text
2022-08-01 21:27:49.515 ERROR 48928 --- [ateHandler.test] r$CustomErrorLogRejectedExecutionHandler : 线程池抛出拒绝策略
```

:::note
具体参考 `hippo4j-example/hippo4j-spring-boot-starter-example` 模块。
:::
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
---
sidebar_position: 0
---

# 内置拒绝策略

内置两种拒绝策略说明:

**RunsOldestTaskPolicy**:添加新任务并由主线程运行最早的任务。

```java
public class RunsOldestTaskPolicy implements RejectedExecutionHandler {

@Override
public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) {
if (executor.isShutdown()) {
return;
}
BlockingQueue<Runnable> workQueue = executor.getQueue();
Runnable firstWork = workQueue.poll();
boolean newTaskAdd = workQueue.offer(r);
if (firstWork != null) {
firstWork.run();
}
if (!newTaskAdd) {
executor.execute(r);
}
}
}
```

**SyncPutQueuePolicy**:主线程把拒绝任务以阻塞的方式添加到队列。

```java
@Slf4j
public class SyncPutQueuePolicy implements RejectedExecutionHandler {

@Override
public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) {
if (executor.isShutdown()) {
return;
}
try {
executor.getQueue().put(r);
} catch (InterruptedException e) {
log.error("Adding Queue task to thread pool failed.", e);
}
}
}
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"label": "快速开始",
"position": 3,
"link": {
"type": "generated-index"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"label": "依赖配置中心",
"position": 2,
"collapsed": true
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
---
sidebar_position: 4
---

# 参数默认配置

曾有多名小伙伴反馈说,项目中线程池一多,配置文件中配置就显得很臃肿。为此 hippo4j-config 开发出了动态线程池默认配置。

```yaml
spring:
dynamic:
thread-pool:
default-executor:
core-pool-size: 4
maximum-pool-size: 6
blocking-queue: ResizableCapacityLinkedBlockingQueue
queue-capacity: 1024
execute-time-out: 1000
keep-alive-time: 9999
rejected-handler: AbortPolicy
active-alarm: 90
capacity-alarm: 85
alarm: true
allow-core-thread-time-out: true
notify:
interval: 5
receives: chen.ma
executors:
- thread-pool-id: message-produce
- thread-pool-id: message-consume
core-pool-size: 80
maximum-pool-size: 100
execute-time-out: 1000
notify:
interval: 6
receives: chen.ma
```
`spring.dynamic.thread-pool.executors` 层级下,仅需要配置 `thread-pool-id`,其余配置从 `spring.dynamic.thread-pool.default-executor` 读取。

如果 `spring.dynamic.thread-pool.executors` 下配置和 `spring.dynamic.thread-pool.default-executor` 冲突,以前者为主。

通过该自定义配置方式,可减少大量重复线程池参数配置项,提高核心配置简洁度。

提示:`spring.dynamic.thread-pool.default-executor` 层级下参数,不提供动态刷新功能。
Loading

0 comments on commit 5fc2906

Please sign in to comment.