|
|
@ -1,8 +1,6 @@
|
|
|
|
package cn.hippo4j.example.core.config;
|
|
|
|
package cn.hippo4j.example.core.config;
|
|
|
|
|
|
|
|
|
|
|
|
import cn.hippo4j.core.executor.DynamicThreadPool;
|
|
|
|
import cn.hippo4j.core.executor.DynamicThreadPool;
|
|
|
|
import cn.hippo4j.core.executor.DynamicThreadPoolExecutor;
|
|
|
|
|
|
|
|
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.handler.TaskTraceBuilderHandler;
|
|
|
|
import cn.hippo4j.example.core.inittest.TaskDecoratorTest;
|
|
|
|
import cn.hippo4j.example.core.inittest.TaskDecoratorTest;
|
|
|
@ -25,44 +23,42 @@ import static cn.hippo4j.example.core.constant.GlobalTestConstant.MESSAGE_PRODUC
|
|
|
|
@Configuration
|
|
|
|
@Configuration
|
|
|
|
public class ThreadPoolConfig {
|
|
|
|
public class ThreadPoolConfig {
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* {@link DynamicThreadPoolWrapper} 完成 Server 端订阅配置功能.
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @return
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
@Bean
|
|
|
|
@Bean
|
|
|
|
public DynamicThreadPoolWrapper messageCenterDynamicThreadPool() {
|
|
|
|
@DynamicThreadPool
|
|
|
|
|
|
|
|
public ThreadPoolExecutor messageConsumeDynamicThreadPool() {
|
|
|
|
|
|
|
|
String threadPoolId = MESSAGE_CONSUME;
|
|
|
|
ThreadPoolExecutor customExecutor = ThreadPoolBuilder.builder()
|
|
|
|
ThreadPoolExecutor customExecutor = ThreadPoolBuilder.builder()
|
|
|
|
.dynamicPool()
|
|
|
|
.dynamicPool()
|
|
|
|
|
|
|
|
.threadFactory(threadPoolId)
|
|
|
|
|
|
|
|
.threadPoolId(threadPoolId)
|
|
|
|
.executeTimeOut(800L)
|
|
|
|
.executeTimeOut(800L)
|
|
|
|
|
|
|
|
.waitForTasksToCompleteOnShutdown(true)
|
|
|
|
|
|
|
|
.awaitTerminationMillis(5000L)
|
|
|
|
.taskDecorator(new TaskTraceBuilderHandler())
|
|
|
|
.taskDecorator(new TaskTraceBuilderHandler())
|
|
|
|
.threadFactory(MESSAGE_CONSUME)
|
|
|
|
|
|
|
|
.build();
|
|
|
|
.build();
|
|
|
|
|
|
|
|
|
|
|
|
return new DynamicThreadPoolWrapper(MESSAGE_CONSUME, customExecutor);
|
|
|
|
return customExecutor;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 通过 {@link DynamicThreadPool} 修饰 {@link DynamicThreadPoolExecutor} 完成 Server 端订阅配置功能.
|
|
|
|
|
|
|
|
* <p>
|
|
|
|
|
|
|
|
* 由动态线程池注解修饰后, IOC 容器中保存的是 {@link DynamicThreadPoolExecutor}
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @return
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
@Bean
|
|
|
|
@Bean
|
|
|
|
@DynamicThreadPool
|
|
|
|
@DynamicThreadPool
|
|
|
|
public ThreadPoolExecutor dynamicThreadPoolExecutor() {
|
|
|
|
public ThreadPoolExecutor messageProduceDynamicThreadPool() {
|
|
|
|
return ThreadPoolBuilder.builder()
|
|
|
|
String threadPoolId = MESSAGE_PRODUCE;
|
|
|
|
.threadFactory(MESSAGE_PRODUCE)
|
|
|
|
ThreadPoolExecutor produceExecutor = ThreadPoolBuilder.builder()
|
|
|
|
.dynamicPool()
|
|
|
|
.dynamicPool()
|
|
|
|
|
|
|
|
.threadFactory(threadPoolId)
|
|
|
|
|
|
|
|
.threadPoolId(threadPoolId)
|
|
|
|
|
|
|
|
.executeTimeOut(900L)
|
|
|
|
|
|
|
|
.waitForTasksToCompleteOnShutdown(true)
|
|
|
|
|
|
|
|
.awaitTerminationMillis(5000L)
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 测试线程任务装饰器.
|
|
|
|
* 测试线程任务装饰器.
|
|
|
|
* 如果需要查看详情, 跳转 {@link TaskDecoratorTest}
|
|
|
|
* 如果需要查看详情, 跳转 {@link TaskDecoratorTest}
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
.waitForTasksToCompleteOnShutdown(true)
|
|
|
|
|
|
|
|
.awaitTerminationMillis(5000)
|
|
|
|
|
|
|
|
.taskDecorator(new TaskDecoratorTest.ContextCopyingDecorator())
|
|
|
|
.taskDecorator(new TaskDecoratorTest.ContextCopyingDecorator())
|
|
|
|
.build();
|
|
|
|
.build();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return produceExecutor;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|