feat: 功能持续更新.

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

@ -1,6 +1,11 @@
package io.dynamic.threadpool.starter.common; 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 class CommonThreadPool {
public static ThreadPoolExecutor getInstance(String threadPoolId) { public static ThreadPoolExecutor getInstance(String threadPoolId) {
TimeUnit unit = TimeUnit.SECONDS; ThreadPoolExecutor poolExecutor = ThreadPoolBuilder.builder()
BlockingQueue workQueue = new LinkedBlockingQueue(512); .threadFactory(threadPoolId)
ThreadPoolExecutor poolExecutor = new ThreadPoolExecutor( .corePoolNum(3)
3, .maxPoolNum(5)
5, .capacity(512)
10000, .keepAliveTime(10000L)
unit, .timeUnit(TimeUnit.SECONDS)
workQueue, .isFastPool(false)
r -> { .rejected(RejectedPolicies.runsOldestTaskPolicy())
Thread thread = new Thread(r); .workQueue(QueueTypeEnum.RESIZABLE_LINKED_BLOCKING_QUEUE)
thread.setDaemon(false); .build();
thread.setName(threadPoolId);
return thread;
});
return poolExecutor; return poolExecutor;
} }
} }

Loading…
Cancel
Save