Provide ExecutorContext encapsulation context details (#557)

* Optimize the thread name produced by thread pool factory

* Provide ExecutorContext encapsulation context details

* Modify class directory
pull/559/head
Lijx 2 years ago committed by GitHub
parent 2b692d0b8f
commit 9d132170c2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,13 @@
package cn.hippo4j.core.executor.support;
import org.slf4j.MDC;
import static cn.hippo4j.common.constant.Constants.EXECUTE_TIMEOUT_TRACE;
public class ExecutorContext {
public static void putExecuteTimeoutTrace(String executeTimeoutTrace) {
MDC.put(EXECUTE_TIMEOUT_TRACE, executeTimeoutTrace);
}
}

@ -18,6 +18,7 @@
package cn.hippo4j.example.core.handler;
import cn.hippo4j.common.toolkit.StringUtil;
import cn.hippo4j.core.executor.support.ExecutorContext;
import org.slf4j.MDC;
import org.springframework.core.task.TaskDecorator;
@ -33,7 +34,7 @@ public final class TaskTraceBuilderHandler implements TaskDecorator {
String executeTimeoutTrace = MDC.get(EXECUTE_TIMEOUT_TRACE);
Runnable taskRun = () -> {
if (StringUtil.isNotBlank(executeTimeoutTrace)) {
MDC.put(EXECUTE_TIMEOUT_TRACE, executeTimeoutTrace);
ExecutorContext.putExecuteTimeoutTrace(executeTimeoutTrace);
}
runnable.run();
// There is no need to clean up here, and it will be cleaned up after the thread task is executed.

Loading…
Cancel
Save