From 3869b115ce1500c366ed1c034d6f3f7fc5a5dc52 Mon Sep 17 00:00:00 2001 From: tjq Date: Mon, 12 Sep 2022 09:36:29 +0800 Subject: [PATCH] feat: optimize RejectedExecutionHandlerFactory --- .../common/RejectedExecutionHandlerFactory.java | 11 ++++------- .../tech/powerjob/server/config/ThreadPoolConfig.java | 2 +- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/powerjob-server/powerjob-server-common/src/main/java/tech/powerjob/server/common/RejectedExecutionHandlerFactory.java b/powerjob-server/powerjob-server-common/src/main/java/tech/powerjob/server/common/RejectedExecutionHandlerFactory.java index e7ea7cc0..e0727763 100644 --- a/powerjob-server/powerjob-server-common/src/main/java/tech/powerjob/server/common/RejectedExecutionHandlerFactory.java +++ b/powerjob-server/powerjob-server-common/src/main/java/tech/powerjob/server/common/RejectedExecutionHandlerFactory.java @@ -21,10 +21,9 @@ public class RejectedExecutionHandlerFactory { * @param source log name * @return A handler for tasks that cannot be executed by ThreadPool */ - public static RejectedExecutionHandler newReject(String source) { + public static RejectedExecutionHandler newDiscard(String source) { return (r, p) -> { - log.error("[{}] ThreadPool[{}] overload, the task[{}] will be dropped!", source, p, r); - log.warn("[{}] Maybe you need to adjust the ThreadPool config!", source); + log.error("[{}] ThreadPool[{}] overload, the task[{}] will be Discard, Maybe you need to adjust the ThreadPool config!", source, p, r); }; } @@ -35,8 +34,7 @@ public class RejectedExecutionHandlerFactory { */ public static RejectedExecutionHandler newCallerRun(String source) { return (r, p) -> { - log.warn("[{}] ThreadPool[{}] overload, the task[{}] will run by caller thread!", source, p, r); - log.warn("[{}] Maybe you need to adjust the ThreadPool config!", source); + log.error("[{}] ThreadPool[{}] overload, the task[{}] will run by caller thread, Maybe you need to adjust the ThreadPool config!", source, p, r); if (!p.isShutdown()) { r.run(); } @@ -50,8 +48,7 @@ public class RejectedExecutionHandlerFactory { */ public static RejectedExecutionHandler newThreadRun(String source) { return (r, p) -> { - log.warn("[{}] ThreadPool[{}] overload, the task[{}] will run by a new thread!", source, p, r); - log.warn("[{}] Maybe you need to adjust the ThreadPool config!", source); + log.error("[{}] ThreadPool[{}] overload, the task[{}] will run by a new thread!, Maybe you need to adjust the ThreadPool config!", source, p, r); if (!p.isShutdown()) { String threadName = source + "-T-" + COUNTER.getAndIncrement(); log.info("[{}] create new thread[{}] to run job", source, threadName); diff --git a/powerjob-server/powerjob-server-starter/src/main/java/tech/powerjob/server/config/ThreadPoolConfig.java b/powerjob-server/powerjob-server-starter/src/main/java/tech/powerjob/server/config/ThreadPoolConfig.java index b9f42e86..ba97cae9 100644 --- a/powerjob-server/powerjob-server-starter/src/main/java/tech/powerjob/server/config/ThreadPoolConfig.java +++ b/powerjob-server/powerjob-server-starter/src/main/java/tech/powerjob/server/config/ThreadPoolConfig.java @@ -46,7 +46,7 @@ public class ThreadPoolConfig { executor.setQueueCapacity(8192); executor.setKeepAliveSeconds(60); executor.setThreadNamePrefix("omsBackgroundPool-"); - executor.setRejectedExecutionHandler(RejectedExecutionHandlerFactory.newReject("PowerJobBackgroundPool")); + executor.setRejectedExecutionHandler(RejectedExecutionHandlerFactory.newDiscard("PowerJobBackgroundPool")); return executor; }