Refactoring thread pool sample code

pull/218/head
chen.ma 2 years ago
parent 4e6100e55d
commit b281c150c1

@ -53,7 +53,6 @@ public class ThreadPoolConfig {
.awaitTerminationMillis(5000L)
.taskDecorator(new TaskTraceBuilderHandler())
.build();
return customExecutor;
}
@ -69,12 +68,10 @@ public class ThreadPoolConfig {
.waitForTasksToCompleteOnShutdown(true)
.awaitTerminationMillis(5000L)
/**
* 线.
* , {@link TaskDecoratorTest}
* {@link TaskDecoratorTest}
*/
.taskDecorator(new TaskDecoratorTest.ContextCopyingDecorator())
.build();
return produceExecutor;
}

@ -49,7 +49,5 @@ public class ErrorLogRejectedExecutionHandler implements CustomRejectedExecution
Logger logger = LoggerFactory.getLogger(this.getClass());
logger.error("线程池抛出拒绝策略.");
}
}
}

@ -34,7 +34,6 @@ public final class TaskTraceBuilderHandler implements TaskDecorator {
@Override
public Runnable decorate(Runnable runnable) {
String executeTimeoutTrace = MDC.get(EXECUTE_TIMEOUT_TRACE);
Runnable taskRun = () -> {
if (StringUtil.isNotBlank(executeTimeoutTrace)) {
MDC.put(EXECUTE_TIMEOUT_TRACE, executeTimeoutTrace);
@ -42,8 +41,6 @@ public final class TaskTraceBuilderHandler implements TaskDecorator {
runnable.run();
// 此处不用进行清理操作, 统一在线程任务执行后清理
};
return taskRun;
}
}

@ -56,5 +56,4 @@ public class AlarmSendMessageTest {
}
}, 3, 1, TimeUnit.SECONDS);
}
}

@ -69,7 +69,6 @@ public class RunStateHandlerTest {
// 启动动态线程池模拟运行任务
runTask(messageConsumeDynamicThreadPool);
// 启动动态线程池模拟运行任务
runTask(messageProduceDynamicThreadPool);
}
@ -102,11 +101,8 @@ public class RunStateHandlerTest {
} catch (Exception ex) {
// ignore
}
ThreadUtil.sleep(500);
}
});
}
}

@ -74,7 +74,6 @@ public class TaskDecoratorTest {
log.info("通过 taskDecorator MDC 传递上下文 :: {}", MDC.get(PLACEHOLDER));
});
});
}
public static class ContextCopyingDecorator implements TaskDecorator {
@ -93,5 +92,4 @@ public class TaskDecoratorTest {
};
}
}
}

Loading…
Cancel
Save