From 0cc81815ecf24df735dbc58bf5986009223de723 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B8=94=E6=B0=91=E5=B0=8F=E9=95=87?= <262610965@qq.com> Date: Sat, 10 Aug 2024 15:27:15 +0800 Subject: [PATCH] =?UTF-8?q?:whale:=20#350=20=E4=BF=AE=E5=A4=8D=E8=AF=B7?= =?UTF-8?q?=E6=B1=82=E6=B6=88=E6=81=AF=E5=9C=A8=20Broker=20=E7=8E=AF?= =?UTF-8?q?=E8=8A=82=E4=B9=B1=E5=BA=8F=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DefaultUserProcessorExecutorStrategy.java | 26 +++++++++++++------ 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/net-bolt/bolt-core/src/main/java/com/iohao/game/bolt/broker/core/common/DefaultUserProcessorExecutorStrategy.java b/net-bolt/bolt-core/src/main/java/com/iohao/game/bolt/broker/core/common/DefaultUserProcessorExecutorStrategy.java index 325001014..bc7bea5bc 100644 --- a/net-bolt/bolt-core/src/main/java/com/iohao/game/bolt/broker/core/common/DefaultUserProcessorExecutorStrategy.java +++ b/net-bolt/bolt-core/src/main/java/com/iohao/game/bolt/broker/core/common/DefaultUserProcessorExecutorStrategy.java @@ -58,20 +58,30 @@ public Executor getExecutor(UserProcessorExecutorAware userProcessorExecutorAwar } String userProcessorName = userProcessorExecutorAware.getClass().getSimpleName(); - if ("RequestMessageClientProcessor".equals(userProcessorName)) { - // 单独一个池 - return ofExecutor("RequestMessage"); - } - return ofExecutor("common"); + return switch (userProcessorName) { + // RequestMessage 相关的单独一个池,使用单线程传递请求消息。 + case "RequestMessageClientProcessor" -> ofExecutorRequestMessage(); + case "RequestMessageBrokerProcessor" -> ofExecutorRequestMessage(); + // 其他 UserProcessor 使用 common 多线程消费任务 + default -> ofExecutorCommon(); + }; + } + + private Executor ofExecutorRequestMessage() { + // 使用单线程传递请求消息 + return ofExecutorCommon("RequestMessage", 1); } - Executor ofExecutor(String name) { + private Executor ofExecutorCommon() { + int corePoolSize = RuntimeKit.availableProcessors; + return ofExecutorCommon("common", corePoolSize); + } + private Executor ofExecutorCommon(String name, int corePoolSize) { Executor executor = this.executorMap.get(name); if (Objects.isNull(executor)) { - int corePoolSize = RuntimeKit.availableProcessors; var tempExecutor = createExecutor(name, corePoolSize, corePoolSize); executor = MoreKit.firstNonNull(this.executorMap.putIfAbsent(name, tempExecutor), tempExecutor); @@ -84,7 +94,7 @@ Executor ofExecutor(String name) { return executor; } - Executor createExecutor(String userProcessorName, int corePoolSize, int maximumPoolSize) { + private Executor createExecutor(String userProcessorName, int corePoolSize, int maximumPoolSize) { /* * 下面对于 UserProcessor 提供了一些默认的 Executor 配置,