ThreadPoolExecutor 引數解析

2021-09-12 01:19:18 字數 1194 閱讀 2609

threadpoolexecutor 主要有以下幾個引數:

public threadpoolexecutor(int corepoolsize,

int maximumpoolsize,

long keepalivetime,

timeunit unit,

blockingqueueworkqueue,

threadfactory threadfactory,

rejectedexecutionhandler handler)

複製**

corepoolsize 核心執行緒數量

maximumpoolsize 最大執行緒數

keepalivetime timeunit 執行緒空閒時間

workqueue 任務佇列

threadfactory 建立執行緒的工廠

private static class customthreadfactory implements threadfactory 

@override

public thread newthread(@nonnull runnable runnable)

if (thread.getpriority() != thread.norm_priority)

return thread;}}

複製**

rejectedexecutionhandler 執行緒數和佇列都滿的情況下,對新新增的任務的處理方式

下面是自定義實現,相當於discardpolicy,只列印異常資訊

private static class customrejectedexecutionhandler implements rejectedexecutionhandler 

@override

public void rejectedexecution(runnable r, threadpoolexecutor e)

}複製**

private final threadpoolexecutor mexecutor;

private threadpoolmanager

() public void executor(@nonnull runnable runnable)

複製**

ThreadPoolExecutor引數設定

1 首先預估系統負載,需要以下幾個值 tasks 每秒的任務數,假設為50 100 tasktime 每個任務花費時間,假設為0.1s responsetime 系統允許容忍的最大響應時間,假設為30s 2 計算 1 corepoolsize 每個任務需要tasktime秒處理,則每個執行緒每秒可處...

Django cms show menu引數解釋

當頁面結構設定 admin cms page 如下 home level 0 about us level 1 about company services level 2 foo bar level 3 our management team level 2 some other section ...

ThreadPoolExecutor使用小結

記錄一下那幾個引數的理解,網上說了亂七八糟,詳細看參考文件,很詳細很明白,沒什麼好說的。corepoolsize,maximumpoolsize,keepalivetime keepalivetime workqueue queue blocksize 執行執行緒後,會判斷數量是否超出corepoo...