添加测试用例.

pull/131/head
chen.ma 3 years ago
parent bfe5626853
commit cfe5a11778

@ -38,6 +38,7 @@ spring:
maximum-pool-size: 1 maximum-pool-size: 1
queue-capacity: 1 queue-capacity: 1
blocking-queue: 'LinkedBlockingQueue' blocking-queue: 'LinkedBlockingQueue'
executeTimeOut: 1000
rejected-handler: 'AbortPolicy' rejected-handler: 'AbortPolicy'
keep-alive-time: 6691 keep-alive-time: 6691
allow-core-thread-time-out: true allow-core-thread-time-out: true

@ -4,6 +4,7 @@ import cn.hippo4j.core.executor.DynamicThreadPool;
import cn.hippo4j.core.executor.DynamicThreadPoolExecutor; import cn.hippo4j.core.executor.DynamicThreadPoolExecutor;
import cn.hippo4j.core.executor.DynamicThreadPoolWrapper; import cn.hippo4j.core.executor.DynamicThreadPoolWrapper;
import cn.hippo4j.core.executor.support.ThreadPoolBuilder; import cn.hippo4j.core.executor.support.ThreadPoolBuilder;
import cn.hippo4j.example.core.handler.TaskTraceBuilderHandler;
import cn.hippo4j.example.core.inittest.TaskDecoratorTest; import cn.hippo4j.example.core.inittest.TaskDecoratorTest;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
@ -34,7 +35,9 @@ public class ThreadPoolConfig {
ThreadPoolExecutor customExecutor = ThreadPoolBuilder.builder() ThreadPoolExecutor customExecutor = ThreadPoolBuilder.builder()
.dynamicPool() .dynamicPool()
.threadFactory(MESSAGE_CONSUME) .threadFactory(MESSAGE_CONSUME)
.taskTraceBuilder(new TaskTraceBuilderHandler())
.build(); .build();
return new DynamicThreadPoolWrapper(MESSAGE_CONSUME, customExecutor); return new DynamicThreadPoolWrapper(MESSAGE_CONSUME, customExecutor);
} }

@ -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);
}
}
Loading…
Cancel
Save