refactor: 重构线程池创建.

pull/161/head
chen.ma 3 years ago
parent 1db5896953
commit d6bb0c378a

@ -1,8 +1,9 @@
package io.dynamic.threadpool.starter.adapter; package io.dynamic.threadpool.starter.adapter;
import cn.hutool.core.thread.ThreadFactoryBuilder;
import io.dynamic.threadpool.common.config.ApplicationContextHolder; import io.dynamic.threadpool.common.config.ApplicationContextHolder;
import io.dynamic.threadpool.common.enums.QueueTypeEnum;
import io.dynamic.threadpool.starter.operation.ThreadPoolOperation; import io.dynamic.threadpool.starter.operation.ThreadPoolOperation;
import io.dynamic.threadpool.starter.toolkit.thread.ThreadPoolBuilder;
import io.dynamic.threadpool.starter.wrap.DynamicThreadPoolWrap; import io.dynamic.threadpool.starter.wrap.DynamicThreadPoolWrap;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.annotation.Order; import org.springframework.core.annotation.Order;
@ -11,7 +12,6 @@ import javax.annotation.PostConstruct;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@ -27,14 +27,13 @@ public class ThreadPoolConfigAdapter extends ConfigAdapter {
@Autowired @Autowired
private ThreadPoolOperation threadPoolOperation; private ThreadPoolOperation threadPoolOperation;
private ExecutorService executorService = new ThreadPoolExecutor( private ExecutorService executorService = ThreadPoolBuilder.builder()
2, .poolThreadNum(2, 4)
4, .keepAliveTime(0L, TimeUnit.MILLISECONDS)
0, .workQueue(QueueTypeEnum.ARRAY_BLOCKING_QUEUE, 1)
TimeUnit.MILLISECONDS, .threadFactory("threadPool-config")
new ArrayBlockingQueue(1), .rejected(new ThreadPoolExecutor.DiscardOldestPolicy())
new ThreadFactoryBuilder().setNamePrefix("threadPool-config").build(), .build();
new ThreadPoolExecutor.DiscardOldestPolicy());
@Order(1025) @Order(1025)
@PostConstruct @PostConstruct

Loading…
Cancel
Save