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(); } }; }