feat: 功能持续更新.

pull/161/head
chen.ma 3 years ago
parent 5383861e2f
commit 7225553d40

@ -1,6 +1,11 @@
package io.dynamic.threadpool.starter.common;
import java.util.concurrent.*;
import io.dynamic.threadpool.common.enums.QueueTypeEnum;
import io.dynamic.threadpool.starter.builder.ThreadPoolBuilder;
import io.dynamic.threadpool.starter.toolkit.thread.RejectedPolicies;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
/**
* 线
@ -11,20 +16,17 @@ import java.util.concurrent.*;
public class CommonThreadPool {
public static ThreadPoolExecutor getInstance(String threadPoolId) {
TimeUnit unit = TimeUnit.SECONDS;
BlockingQueue workQueue = new LinkedBlockingQueue(512);
ThreadPoolExecutor poolExecutor = new ThreadPoolExecutor(
3,
5,
10000,
unit,
workQueue,
r -> {
Thread thread = new Thread(r);
thread.setDaemon(false);
thread.setName(threadPoolId);
return thread;
});
ThreadPoolExecutor poolExecutor = ThreadPoolBuilder.builder()
.threadFactory(threadPoolId)
.corePoolNum(3)
.maxPoolNum(5)
.capacity(512)
.keepAliveTime(10000L)
.timeUnit(TimeUnit.SECONDS)
.isFastPool(false)
.rejected(RejectedPolicies.runsOldestTaskPolicy())
.workQueue(QueueTypeEnum.RESIZABLE_LINKED_BLOCKING_QUEUE)
.build();
return poolExecutor;
}
}

Loading…
Cancel
Save