Skip to content

Commit 7a8833a

Browse files
committed
use new thread pool
1 parent 3a34ff8 commit 7a8833a

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

taskscheduler/src/main/java/com/silencedut/taskscheduler/TaskScheduler.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ public class TaskScheduler {
3737
private static final int CPU_COUNT = Runtime.getRuntime().availableProcessors();
3838
private static final int MAXIMUM_POOL_SIZE = CPU_COUNT * 2 + 1;
3939
private static final long KEEP_ALIVE = 60L;
40-
private static final BlockingQueue<Runnable> sPoolWorkQueue =
41-
new LinkedBlockingQueue<Runnable>();
40+
private static final BlockingQueue<Runnable> POOL_WORK_QUEUE =
41+
new LinkedBlockingQueue<>(128);
4242

4343
private static TaskScheduler getInstance() {
4444
if(sTaskScheduler==null) {
@@ -57,7 +57,7 @@ private TaskScheduler() {
5757
mParallelExecutor 直接使用AsyncTask的线程,减少新线程创建带来的资源消耗
5858
*/
5959
mParallelExecutor = new ThreadPoolExecutor(CPU_COUNT,MAXIMUM_POOL_SIZE,
60-
KEEP_ALIVE,TimeUnit.SECONDS,sPoolWorkQueue,ThreadFactory.TASKSCHEDULER_FACTORY);
60+
KEEP_ALIVE,TimeUnit.SECONDS,POOL_WORK_QUEUE,ThreadFactory.TASKSCHEDULER_FACTORY);
6161

6262
/*
6363
没有核心线程的线程池要用 SynchronousQueue 而不是LinkedBlockingQueue,SynchronousQueue是一个只有一个任务的队列,

0 commit comments

Comments
 (0)