From 2706bfb3b690de6396ec5a021e749c4131df2670 Mon Sep 17 00:00:00 2001 From: irving Date: Sat, 1 Nov 2025 23:55:21 -0400 Subject: [PATCH] =?UTF-8?q?perf(common):=20=E4=BC=98=E5=8C=96=E7=BA=BF?= =?UTF-8?q?=E7=A8=8B=E6=B1=A0=E5=8F=82=E6=95=B0=E4=B8=8E=E8=AF=B7=E6=B1=82?= =?UTF-8?q?=E6=97=A5=E5=BF=97=EF=BC=8C=E9=99=8D=E4=BD=8E=E5=99=AA=E9=9F=B3?= =?UTF-8?q?=E5=B9=B6=E6=8F=90=E5=8D=87=E5=8F=AF=E8=A7=82=E6=B5=8B=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/starry/common/config/ThreadPoolConfig.java | 3 +++ .../interceptor/RequestLoggingInterceptor.java | 13 +++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/play-common/src/main/java/com/starry/common/config/ThreadPoolConfig.java b/play-common/src/main/java/com/starry/common/config/ThreadPoolConfig.java index a30810f..5847499 100644 --- a/play-common/src/main/java/com/starry/common/config/ThreadPoolConfig.java +++ b/play-common/src/main/java/com/starry/common/config/ThreadPoolConfig.java @@ -40,6 +40,9 @@ public class ThreadPoolConfig { executor.setCorePoolSize(corePoolSize); executor.setQueueCapacity(queueCapacity); executor.setKeepAliveSeconds(keepAliveSeconds); + executor.setThreadNamePrefix("async-pool-"); + executor.setWaitForTasksToCompleteOnShutdown(true); + executor.setAwaitTerminationSeconds(30); // 线程池对拒绝任务(无线程可用)的处理策略 executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy()); return executor; diff --git a/play-common/src/main/java/com/starry/common/interceptor/RequestLoggingInterceptor.java b/play-common/src/main/java/com/starry/common/interceptor/RequestLoggingInterceptor.java index b88ae78..0c96a78 100644 --- a/play-common/src/main/java/com/starry/common/interceptor/RequestLoggingInterceptor.java +++ b/play-common/src/main/java/com/starry/common/interceptor/RequestLoggingInterceptor.java @@ -8,6 +8,7 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; import org.springframework.web.servlet.HandlerInterceptor; @@ -25,6 +26,9 @@ public class RequestLoggingInterceptor implements HandlerInterceptor { private static final String START_TIME_ATTRIBUTE = "startTime"; public static final String BUSINESS_RESULT_ATTRIBUTE = "requestLoggingBusinessResult"; + @Value("${logging.business-error-as-warn:false}") + private boolean businessErrorAsWarn; + @Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { @@ -208,8 +212,13 @@ public class RequestLoggingInterceptor implements HandlerInterceptor { long duration, BusinessResult businessResult) { String template = "Request completed: {} {} - {} {} ({}ms) businessCode={} success={} message={}"; if (isBusinessError(businessResult)) { - log.error(template, method, uri, status, statusText, duration, - businessResult.getCode(), businessResult.isSuccess(), businessResult.getMessage()); + if (businessErrorAsWarn) { + log.warn(template, method, uri, status, statusText, duration, + businessResult.getCode(), businessResult.isSuccess(), businessResult.getMessage()); + } else { + log.error(template, method, uri, status, statusText, duration, + businessResult.getCode(), businessResult.isSuccess(), businessResult.getMessage()); + } } else if (isBusinessWarn(businessResult)) { log.warn(template, method, uri, status, statusText, duration, businessResult.getCode(), businessResult.isSuccess(), businessResult.getMessage());