ThreadPool full問題排查

2021-10-20 01:52:43 字數 2990 閱讀 8019

目前lex業務場景包含兩個模組:fm、linehaulshuttle,都是通過odps離線同步然後通過blink傳送到gateway的mq,兩個qps分別是:fm-1000/s,linehaulshuttle-600/s,會對系統有個短暫的衝擊,目前系統未經過壓測,所以對於系統的抗壓能力我們是不清楚的,如下就是接入linhaul場景時發現的異常:執行緒池佔滿

由於lindorm入庫、發風控是使用了執行緒池非同步操作的,這樣不僅能提高系統處理效率還能提高吞吐量,但是由於執行緒資源有限,所以就會發生如上的異常,檢視**:

可以發現兩個問題:

當前執行緒池使用的策略是:abortpolicy,這將導致達到最大執行緒數時,新任務將直接被丟棄

@enableasync

@configuration

public

class

asyncthreadpoolconfig

if(thread.

getpriority()

!= thread.norm_priority)

return thread;}}

);// 執行緒池對拒絕任務的處理策略,拒絕執行且丟擲異常

executor.

setrejectedexecutionhandler

(new

threadpoolexecutor.abortpolicy()

);// 初始化

executor.

initialize()

;return executor;

}}

本地驗證復現該問題

將核心/最大執行緒數改為:5,緩衝區大小改為:5

private

static

final

int core_pool_size =5;

private

static

final

int queue_capacity =

5;

private atomicinteger atomicinteger =

newatomicinteger(0

);@async

("asynctaskexecutor"

)public

void

test()

catch

(interruptedexception e)

system.out.

println

("handle over: "

+ index)

;}

@runwith

(pandorabootrunner.

class

)@delegateto

(springjunit4classrunner.

class

)@springboottest

(classes =

class})

public

class

asyncthreadpoolconfigtest

extends

testcase

system.out.

println

("testasynctaskexecutor over");

}}

發現當執行到10個任務的時候,執行緒池就拒絕執行後面來的新任務了。

插曲疑問:為什麼之前處理完的執行緒沒有繼續執行後續的任務呢?

經排查發現是由於執行緒池的異常拋到主線程導致程式中斷了

修改test方法

private atomicinteger atomicinteger =

newatomicinteger(0

);@autowired

private threadpooltaskexecutor executor;

public

void

test()

catch

(interruptedexception e)

system.out.

println

("handle over: "

+ index);}

);}catch

(exception e)

}

最終結果

總計處理任務100個,其中失敗70個,成功30個

思路:修改**

修改飽和策略為callerrunspolicy,其他保持不變

executor.

setrejectedexecutionhandler

(new

threadpoolexecutor.callerrunspolicy()

);

測試結果

總計處理任務100,其中失敗0個,成功100個

修改生效,任務不會因為執行緒池滿而被丟棄

最終**

@enableasync

@configuration

public

class

asyncthreadpoolconfig

if(thread.

getpriority()

!= thread.norm_priority)

return thread;}}

);// 如果執行緒池滿了之後,使用當前工作執行緒來處理任務

executor.

setrejectedexecutionhandler

(new

threadpoolexecutor.callerrunspolicy()

);// 初始化

executor.

initialize()

;return executor;

}}

小金問呀問不會問題

problem description 眾所周知,c語言的學習是我們程式設計基礎的重點和主要內容。小金在班裡是乙個愛學習的好孩子,但是他的程式設計能力卻有點差,不過他堅信自己一定可以進步並追上其他同學。input 多組輸入。從鍵盤讀入乙個整數n,如果n 0代表小金考試進步了,如果n 0代表小金退步了...

小金問呀問不會問題

problem description 眾所周知,c語言的學習是我們程式設計基礎的重點和主要內容。小金在班裡是乙個愛學習的好孩子,但是他的程式設計能力卻有點差,不過他堅信自己一定可以進步並追上其他同學。input 多組輸入。從鍵盤讀入乙個整數n,如果n 0代表小金考試進步了,如果n 0代表小金退步了...

unauthenticated user 問題解決

今天公司資料庫出現了停頓和阻塞的問題,檢查資料庫的時候發現,show processlist 可以看到大量 3436942 unauthenticated user 192.168.0.4 49607 connect login 3436943 unauthenticated user 192.16...