From c8ca23d1f67d76143fb294e728b2e9a5d6ff65f2 Mon Sep 17 00:00:00 2001 From: zhenghaoyu Date: Mon, 6 May 2024 17:00:28 +0800 Subject: [PATCH] =?UTF-8?q?1.=E6=83=B3=E6=88=90=E6=95=B0=E6=8D=AE=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../trunkline/config/ExecutorConfig.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/blade-service/logpm-trunkline/src/main/java/com/logpm/trunkline/config/ExecutorConfig.java b/blade-service/logpm-trunkline/src/main/java/com/logpm/trunkline/config/ExecutorConfig.java index 7257f2152..b9903d9d1 100644 --- a/blade-service/logpm-trunkline/src/main/java/com/logpm/trunkline/config/ExecutorConfig.java +++ b/blade-service/logpm-trunkline/src/main/java/com/logpm/trunkline/config/ExecutorConfig.java @@ -1,6 +1,9 @@ package com.logpm.trunkline.config; import lombok.extern.slf4j.Slf4j; +import org.slf4j.MDC; +import org.springblade.core.secure.utils.AuthUtil; +import org.springblade.core.tool.utils.ThreadLocalUtil; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.core.task.TaskDecorator; @@ -10,6 +13,7 @@ import org.springframework.web.context.request.RequestAttributes; import org.springframework.web.context.request.RequestContextHolder; import javax.annotation.Nonnull; +import java.util.Map; import java.util.concurrent.Executor; import java.util.concurrent.ThreadPoolExecutor; @@ -49,12 +53,27 @@ public class ExecutorConfig { @Override public Runnable decorate(@Nonnull Runnable runnable) { RequestAttributes context = RequestContextHolder.currentRequestAttributes(); + String tenantId = AuthUtil.getTenantId(); + Map all = ThreadLocalUtil.getAll(); + Map mdcMap = MDC.getCopyOfContextMap(); return () -> { try { + all.keySet().forEach(key -> ThreadLocalUtil.put(key, all.get(key))); + if (mdcMap != null && !mdcMap.isEmpty()) { + MDC.setContextMap(mdcMap); + } RequestContextHolder.setRequestAttributes(context); + String tenantId1 = AuthUtil.getTenantId(); + runnable.run(); } finally { RequestContextHolder.resetRequestAttributes(); + all.clear(); + if (mdcMap != null) { + mdcMap.clear(); + } + ThreadLocalUtil.clear(); + MDC.clear(); } }; }