Commit f01acec1 authored by 杨锐's avatar 杨锐

cn.quantgroup.tech.brave.service.ITechExecutorServiceBuilder#buildExecutorService

parent 1e7fac18
......@@ -10,9 +10,5 @@ import java.util.concurrent.*;
*/
public interface ITechExecutorServiceBuilder {
ExecutorService buildExecutorService(int corePoolSize,
int maxPoolSize,
int queueCapacity,
String threadNamePrefix,
RejectedExecutionHandler rejectedExecutionHandler);
ExecutorService buildExecutorService(ExecutorService executorService);
}
......@@ -2,10 +2,9 @@ package cn.quantgroup.tech.brave.service.impl;
import cn.quantgroup.tech.brave.service.ITechExecutorServiceBuilder;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Component;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.RejectedExecutionHandler;
/**
* Date: 2020/1/6
......@@ -14,23 +13,10 @@ import java.util.concurrent.RejectedExecutionHandler;
* @author: yangrui
*/
@Slf4j
@Component
public class TechExecutorServiceBuilderNoTrace implements ITechExecutorServiceBuilder {
@Override
public ExecutorService buildExecutorService(int corePoolSize,
int maxPoolSize,
int queueCapacity,
String threadNamePrefix,
RejectedExecutionHandler rejectedExecutionHandler) {
log.info("构建TechExecutorServiceBuilderNoTrace, corePoolSize = 【{}】, maxPoolSize = 【{}】, queueCapacity = 【{}】, " +
"threadNamePrefix = 【{}】, rejectedExecutionHandler = 【{}】", corePoolSize, maxPoolSize, queueCapacity,
threadNamePrefix, rejectedExecutionHandler);
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
executor.setCorePoolSize(corePoolSize);
executor.setMaxPoolSize(maxPoolSize);
executor.setQueueCapacity(queueCapacity);
executor.setThreadNamePrefix(threadNamePrefix);
executor.setRejectedExecutionHandler(rejectedExecutionHandler);
executor.initialize();
return executor.getThreadPoolExecutor();
public ExecutorService buildExecutorService(ExecutorService executorService) {
return executorService;
}
}
......@@ -4,36 +4,23 @@ import brave.propagation.CurrentTraceContext;
import cn.quantgroup.tech.brave.service.ITechExecutorServiceBuilder;
import cn.quantgroup.tech.brave.slf4j.MDCCurrentTraceContext;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Component;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.RejectedExecutionHandler;
/**
* zipkin线程池追踪一致性
* Date: 2020/1/6
* Time: 下午4:52
*
* @author: yangrui
*/
@Slf4j
@Component
public class TechExecutorServiceBuilderTrace implements ITechExecutorServiceBuilder {
@Override
public ExecutorService buildExecutorService(int corePoolSize,
int maxPoolSize,
int queueCapacity,
String threadNamePrefix,
RejectedExecutionHandler rejectedExecutionHandler) {
log.info("构建TechExecutorServiceBuilderTrace, corePoolSize = 【{}】, maxPoolSize = 【{}】, queueCapacity = 【{}】, " +
"threadNamePrefix = 【{}】, rejectedExecutionHandler = 【{}】", corePoolSize, maxPoolSize, queueCapacity,
threadNamePrefix, rejectedExecutionHandler);
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
executor.setCorePoolSize(corePoolSize);
executor.setMaxPoolSize(maxPoolSize);
executor.setQueueCapacity(queueCapacity);
executor.setThreadNamePrefix(threadNamePrefix);
executor.setRejectedExecutionHandler(rejectedExecutionHandler);
executor.initialize();
public ExecutorService buildExecutorService(ExecutorService executorService) {
CurrentTraceContext mdcCurrentTraceContext = MDCCurrentTraceContext.create();
return mdcCurrentTraceContext.executorService(executor.getThreadPoolExecutor());
return mdcCurrentTraceContext.executorService(executorService);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment