From cc4f67a5b08f939720fa0f111dcc301c3590944c Mon Sep 17 00:00:00 2001 From: caojiajun Date: Mon, 13 Feb 2023 14:30:32 +0800 Subject: [PATCH] optimize CamelliaLinearInitializationExecutor --- .../CamelliaLinearInitializationExecutor.java | 3 ++- ...liaLinearInitializationExecutorConfig.java | 21 ++++++++----------- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/camellia-tools/src/main/java/com/netease/nim/camellia/tools/executor/CamelliaLinearInitializationExecutor.java b/camellia-tools/src/main/java/com/netease/nim/camellia/tools/executor/CamelliaLinearInitializationExecutor.java index a6a0932d6..f64fcf29d 100644 --- a/camellia-tools/src/main/java/com/netease/nim/camellia/tools/executor/CamelliaLinearInitializationExecutor.java +++ b/camellia-tools/src/main/java/com/netease/nim/camellia/tools/executor/CamelliaLinearInitializationExecutor.java @@ -42,7 +42,8 @@ public CamelliaLinearInitializationExecutor(CamelliaLinearInitializationExecutor this.initializer = config.getInitializer(); this.config = config; this.name = CamelliaExecutorMonitor.genExecutorName(config.getName()); - this.executor = config.getExecutor(); + this.executor = new CamelliaHashedExecutor("liner-initialization-" + name, config.getPoolSize(), + config.getPendingQueueSize(), new CamelliaHashedExecutor.AbortPolicy()); this.pendingQueueSize = config.getPendingQueueSize(); CamelliaExecutorMonitor.register(this); diff --git a/camellia-tools/src/main/java/com/netease/nim/camellia/tools/executor/CamelliaLinearInitializationExecutorConfig.java b/camellia-tools/src/main/java/com/netease/nim/camellia/tools/executor/CamelliaLinearInitializationExecutorConfig.java index eaa8eab1a..bec444a48 100644 --- a/camellia-tools/src/main/java/com/netease/nim/camellia/tools/executor/CamelliaLinearInitializationExecutorConfig.java +++ b/camellia-tools/src/main/java/com/netease/nim/camellia/tools/executor/CamelliaLinearInitializationExecutorConfig.java @@ -10,21 +10,18 @@ public class CamelliaLinearInitializationExecutorConfig { private String name; private CamelliaLinearInitializationExecutor.Initializer initializer; - private CamelliaHashedExecutor executor; private DynamicValueGetter pendingQueueSize = () -> 100000; + private int poolSize = SysUtils.getCpuNum(); public CamelliaLinearInitializationExecutorConfig(String name, CamelliaLinearInitializationExecutor.Initializer initializer) { this.name = name; this.initializer = initializer; - this.executor = new CamelliaHashedExecutor("liner-initialization-" + name, SysUtils.getCpuNum(), 10000); } public CamelliaLinearInitializationExecutorConfig(String name, CamelliaLinearInitializationExecutor.Initializer initializer, DynamicValueGetter pendingQueueSize) { this.name = name; this.initializer = initializer; - this.executor = new CamelliaHashedExecutor("liner-initialization-" + name, SysUtils.getCpuNum(), - pendingQueueSize, new CamelliaHashedExecutor.AbortPolicy()); this.pendingQueueSize = pendingQueueSize; } @@ -44,14 +41,6 @@ public void setInitializer(CamelliaLinearInitializationExecutor.Initializer getPendingQueueSize() { return pendingQueueSize; } @@ -59,4 +48,12 @@ public DynamicValueGetter getPendingQueueSize() { public void setPendingQueueSize(DynamicValueGetter pendingQueueSize) { this.pendingQueueSize = pendingQueueSize; } + + public int getPoolSize() { + return poolSize; + } + + public void setPoolSize(int poolSize) { + this.poolSize = poolSize; + } }