feat: 功能持续更新.

pull/161/head
chen.ma 3 years ago
parent 7225553d40
commit 7c35e2817a

@ -1,7 +1,7 @@
package io.dynamic.threadpool.starter.common;
import io.dynamic.threadpool.common.enums.QueueTypeEnum;
import io.dynamic.threadpool.starter.builder.ThreadPoolBuilder;
import io.dynamic.threadpool.starter.toolkit.thread.ThreadPoolBuilder;
import io.dynamic.threadpool.starter.toolkit.thread.RejectedPolicies;
import java.util.concurrent.ThreadPoolExecutor;
@ -18,14 +18,10 @@ public class CommonThreadPool {
public static ThreadPoolExecutor getInstance(String threadPoolId) {
ThreadPoolExecutor poolExecutor = ThreadPoolBuilder.builder()
.threadFactory(threadPoolId)
.corePoolNum(3)
.maxPoolNum(5)
.capacity(512)
.keepAliveTime(10000L)
.timeUnit(TimeUnit.SECONDS)
.isFastPool(false)
.poolThreadNum(3, 5)
.keepAliveTime(1000L, TimeUnit.SECONDS)
.rejected(RejectedPolicies.runsOldestTaskPolicy())
.workQueue(QueueTypeEnum.RESIZABLE_LINKED_BLOCKING_QUEUE)
.workQueue(QueueTypeEnum.RESIZABLE_LINKED_BLOCKING_QUEUE, 512)
.build();
return poolExecutor;
}

@ -1,10 +1,10 @@
package io.dynamic.threadpool.starter.builder;
package io.dynamic.threadpool.starter.toolkit.thread;
import io.dynamic.threadpool.common.enums.QueueTypeEnum;
import io.dynamic.threadpool.common.toolkit.Assert;
import io.dynamic.threadpool.starter.builder.Builder;
import io.dynamic.threadpool.starter.toolkit.BlockingQueueUtil;
import io.dynamic.threadpool.starter.toolkit.thread.AbstractBuildThreadPoolTemplate;
import java.math.BigDecimal;
import java.util.concurrent.*;
@ -108,6 +108,12 @@ public class ThreadPoolBuilder implements Builder<ThreadPoolExecutor> {
return this;
}
public ThreadPoolBuilder poolThreadNum(Integer corePoolNum, Integer maxPoolNum) {
this.corePoolNum = corePoolNum;
this.maxPoolNum = maxPoolNum;
return this;
}
public ThreadPoolBuilder keepAliveTime(Long keepAliveTime) {
this.keepAliveTime = keepAliveTime;
return this;
@ -118,11 +124,23 @@ public class ThreadPoolBuilder implements Builder<ThreadPoolExecutor> {
return this;
}
public ThreadPoolBuilder keepAliveTime(Long keepAliveTime, TimeUnit timeUnit) {
this.keepAliveTime = keepAliveTime;
this.timeUnit = timeUnit;
return this;
}
public ThreadPoolBuilder capacity(Integer capacity) {
this.capacity = capacity;
return this;
}
public ThreadPoolBuilder workQueue(QueueTypeEnum queueType, Integer capacity) {
this.queueType = queueType;
this.capacity = capacity;
return this;
}
public ThreadPoolBuilder rejected(RejectedExecutionHandler rejectedExecutionHandler) {
this.rejectedExecutionHandler = rejectedExecutionHandler;
return this;
Loading…
Cancel
Save