Skip to content

Commit

Permalink
添加测试用例.
Browse files Browse the repository at this point in the history
  • Loading branch information
magestacks committed Mar 2, 2022
1 parent bfe5626 commit cfe5a11
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ spring:
maximum-pool-size: 1
queue-capacity: 1
blocking-queue: 'LinkedBlockingQueue'
executeTimeOut: 1000
rejected-handler: 'AbortPolicy'
keep-alive-time: 6691
allow-core-thread-time-out: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import cn.hippo4j.core.executor.DynamicThreadPoolExecutor;
import cn.hippo4j.core.executor.DynamicThreadPoolWrapper;
import cn.hippo4j.core.executor.support.ThreadPoolBuilder;
import cn.hippo4j.example.core.handler.TaskTraceBuilderHandler;
import cn.hippo4j.example.core.inittest.TaskDecoratorTest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
Expand Down Expand Up @@ -34,7 +35,9 @@ public DynamicThreadPoolWrapper messageCenterDynamicThreadPool() {
ThreadPoolExecutor customExecutor = ThreadPoolBuilder.builder()
.dynamicPool()
.threadFactory(MESSAGE_CONSUME)
.taskTraceBuilder(new TaskTraceBuilderHandler())
.build();

return new DynamicThreadPoolWrapper(MESSAGE_CONSUME, customExecutor);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package cn.hippo4j.example.core.handler;

import cn.hippo4j.common.notify.TaskTraceBuilder;
import org.slf4j.MDC;

/**
* Task trace builder handler.
*
* @author chen.ma
* @date 2022/3/2 20:46
*/
public class TaskTraceBuilderHandler implements TaskTraceBuilder {

private final String TRACE_KEY = "traceId";

@Override
public void before() {
MDC.put(TRACE_KEY, "https://github.com/acmenlt/dynamic-threadpool 行行好, 点个 Star.");
}

@Override
public String traceBuild() {
String traceStr;
try {
traceStr = MDC.get(TRACE_KEY);
} finally {
clear();
}

return traceStr;
}

@Override
public void clear() {
MDC.remove(TRACE_KEY);
}

}

0 comments on commit cfe5a11

Please sign in to comment.