forked from opengoofy/hippo4j
-
Notifications
You must be signed in to change notification settings - Fork 0
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
5b5eaba
commit 5f75eb5
Showing
6 changed files
with
123 additions
and
74 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
35 changes: 0 additions & 35 deletions
35
hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/event/EventExecutor.java
This file was deleted.
Oops, something went wrong.
45 changes: 45 additions & 0 deletions
45
hippo4j-spring-boot-starter/src/main/java/cn/hippo4j/starter/event/MonitorEventExecutor.java
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 @@ | ||
package cn.hippo4j.starter.event; | ||
|
||
import cn.hippo4j.common.function.NoArgsConsumer; | ||
import cn.hippo4j.starter.toolkit.thread.QueueTypeEnum; | ||
import cn.hippo4j.starter.toolkit.thread.ThreadPoolBuilder; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
import java.util.concurrent.ExecutorService; | ||
import java.util.concurrent.RejectedExecutionException; | ||
import java.util.concurrent.ThreadPoolExecutor; | ||
|
||
import static cn.hippo4j.common.constant.Constants.AVAILABLE_PROCESSORS; | ||
|
||
/** | ||
* 动态线程池监控事件执行器. | ||
* | ||
* @author chen.ma | ||
* @date 2021/11/8 23:44 | ||
*/ | ||
@Slf4j | ||
public class MonitorEventExecutor { | ||
|
||
private static final ExecutorService EVENT_EXECUTOR = ThreadPoolBuilder.builder() | ||
.threadFactory("monitor-event-executor") | ||
.corePoolSize(AVAILABLE_PROCESSORS) | ||
.maxPoolNum(AVAILABLE_PROCESSORS) | ||
.workQueue(QueueTypeEnum.LINKED_BLOCKING_QUEUE) | ||
.capacity(4096) | ||
.rejected(new ThreadPoolExecutor.AbortPolicy()) | ||
.build(); | ||
|
||
/** | ||
* 发布事件. | ||
* | ||
* @param consumer | ||
*/ | ||
public static void publishEvent(NoArgsConsumer consumer) { | ||
try { | ||
EVENT_EXECUTOR.execute(consumer::accept); | ||
} catch (RejectedExecutionException ex) { | ||
log.error("Monitoring thread pool run events exceeded load."); | ||
} | ||
} | ||
|
||
} |
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