-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e141e5d
commit 5fc2906
Showing
76 changed files
with
3,606 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
...i18n/zh/docusaurus-plugin-content-docs/version-1.5.0/user_docs/dev_manual/_category_.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"label": "开发者手册", | ||
"position": 5, | ||
"link": { | ||
"type": "generated-index", | ||
"description": "Hippo4j 留给使用者能够扩展的知识点。" | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
...lugin-content-docs/version-1.5.0/user_docs/dev_manual/rejected-policy-custom.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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` 模块。 | ||
::: |
50 changes: 50 additions & 0 deletions
50
...-plugin-content-docs/version-1.5.0/user_docs/dev_manual/rejected-policy-info.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} | ||
``` |
7 changes: 7 additions & 0 deletions
7
...zh/docusaurus-plugin-content-docs/version-1.5.0/user_docs/getting_started/_category_.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"label": "快速开始", | ||
"position": 3, | ||
"link": { | ||
"type": "generated-index" | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
...saurus-plugin-content-docs/version-1.5.0/user_docs/getting_started/config/_category_.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"label": "依赖配置中心", | ||
"position": 2, | ||
"collapsed": true | ||
} |
45 changes: 45 additions & 0 deletions
45
...t-docs/version-1.5.0/user_docs/getting_started/config/hippo4j-config-default.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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` 层级下参数,不提供动态刷新功能。 |
Oops, something went wrong.