執行緒池有哪些配置引數,各自的作用是什麼?

2022-01-21 20:46:58 字數 1618 閱讀 7104

5大引數

a.核心執行緒數

b 最大執行緒數

c 執行緒空閒時間

d 阻塞佇列大小:queuecapacity

e 任務拒絕處理器 :rejectedexceptionhandler 

根據jdk 1.7,他又四類建構函式:

1. threadpoolexecutor(int corepoolsize, int maximumpoolsize, long keepalivetime, timeunit unit, blockingqueueworkqueue)

2. threadpoolexecutor(int corepoolsize, int maximumpoolsize, long keepalivetime, timeunit unit, blockingqueueworkqueue, rejectedexecutionhandler handler)

3. threadpoolexecutor(int corepoolsize, int maximumpoolsize, long keepalivetime, timeunit unit, blockingqueueworkqueue, threadfactory threadfactory)

4. threadpoolexecutor(int corepoolsize, int maximumpoolsize, long keepalivetime, timeunit unit, blockingqueueworkqueue, threadfactory threadfactory, rejectedexecutionhandler handler)

實現執行緒池,有四種策略:

1.newcachedthreadpool

jdk 1.6原始碼:

publicstaticexecutorservice newcachedthreadpool()

2 newfixedthreadpool

jdk 1.6原始碼:

publicstaticexecutorservice newfixedthreadpool(

intnthreads)

3 newsinglethreadexecutor

jdk 1.6原始碼:

publicstaticexecutorservice newsinglethreadexecutor()

4 newscheduledthreadpool

jdk 1.6原始碼:

publicstaticscheduledexecutorservice newscheduledthreadpool (

intcorepoolsize)

publicscheduledthreadpoolexecutor(

intcorepoolsize)

執行緒池有哪些引數?

我們首先建立乙個執行緒池 public class threadpoolparameters 當然,上面的引數是隨便填的,進入 executors.newfixedthreadpool裡面,檢視建立 fixedthreadpool執行緒池的原始碼,如下就是它原始碼的一部分 public static...

執行緒池都有哪些核心配置引數?

表示常駐核心執行緒數量。表示執行緒池中能同時執行的最大執行緒數量。這個值必須大於等於corepoolsize,如果這兩個值相等,那就是固定大小的執行緒池 表示執行緒池中除常駐核心執行緒之外的其他執行緒的空閒時間,如果超過這個時間就會銷毀。快取佇列,當請求的執行緒數大於corepoolsize的時候,...

執行緒池的種類有哪些?

目錄 一 可快取執行緒池 newcachedthreadpool 二 指定工作執行緒的執行緒池 newfixedthreadpool 三 定時的執行緒池newscheduledthreadpool 四 單執行緒執行緒池 newsinglethreadexecutor 建立乙個可根據需要建立新執行緒的...