Simplified thread pool creation (#756)

* Simplified thread pool creation

* update method name
pull/759/head
weihubeats 2 years ago committed by GitHub
parent 83fea8e0c7
commit c97b2b407c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -17,14 +17,19 @@
package cn.hippo4j.core.executor.support;
import java.math.BigDecimal;
import java.util.Optional;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.RejectedExecutionHandler;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import cn.hippo4j.common.design.builder.Builder;
import cn.hippo4j.common.executor.support.BlockingQueueTypeEnum;
import cn.hippo4j.common.toolkit.Assert;
import org.springframework.core.task.TaskDecorator;
import java.math.BigDecimal;
import java.util.Optional;
import java.util.concurrent.*;
import org.springframework.core.task.TaskDecorator;
/**
* Thread-pool builder.
@ -221,6 +226,19 @@ public class ThreadPoolBuilder implements Builder<ThreadPoolExecutor> {
return new ThreadPoolBuilder();
}
/**
* Create dynamic thread pool by thread pool id
* @param threadPoolId threadPoolId
* @return ThreadPoolExecutor
*/
public static ThreadPoolExecutor builderDynamicPoolById(String threadPoolId) {
return ThreadPoolBuilder.builder()
.threadFactory(threadPoolId)
.threadPoolId(threadPoolId)
.dynamicPool()
.build();
}
private static ThreadPoolExecutor buildPool(ThreadPoolBuilder builder) {
return AbstractBuildThreadPoolTemplate.buildPool(buildInitParam(builder));
}

@ -17,13 +17,14 @@
package cn.hippo4j.example.config.etcd.config;
import java.util.concurrent.ThreadPoolExecutor;
import cn.hippo4j.core.executor.DynamicThreadPool;
import cn.hippo4j.core.executor.support.ThreadPoolBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import java.util.concurrent.ThreadPoolExecutor;
/**
* @author : wh
* @date : 2022/9/2 19:26
@ -36,11 +37,6 @@ public class ThreadPoolConfig {
@DynamicThreadPool
public ThreadPoolExecutor messageConsumeDynamicExecutor() {
String threadPoolId = "message-consume";
ThreadPoolExecutor messageConsumeDynamicExecutor = ThreadPoolBuilder.builder()
.threadFactory(threadPoolId)
.threadPoolId(threadPoolId)
.dynamicPool()
.build();
return messageConsumeDynamicExecutor;
return ThreadPoolBuilder.builderDynamicPoolById(threadPoolId);
}
}

Loading…
Cancel
Save