jdk--ThreadPoolExecutor1--線程池併發線程數

充分利用CPU多核,每個內核不閒置

 

線程池線程數--->基於Ncpu核數

                           線程任務------計算密集型

                                          -------IO密集型

計算密集型,線程數=CPU核數

              --------------CPU1,沒有IO等待,一直計算執行繁忙

              --------------CPU2,沒有IO等待,一直計算執行繁忙

 

IO密集型,線程數=CPU核數/(1-阻塞係數),                  

當線程任務處於IO狀態,線程阻塞等待狀態,CPU閒置,可以調度等待線程執行,提高效率

                                           

               

                                                                                                         封裝

Executor    new fixedthreadpool  -----------|                                           |

Executor    new signalthreadpool  -----------|     -------------------threadpoolexecutor (new LinkedBlockingQueue)

Executor    new cachedthreadpool ----------|

Executor創建線程池內部調用threadpoolexecutor,產生的問題LinkedBlockingQueue隊列默認Integer.maxvalue無上限,會將內存佔滿,-->OOM

Integer.max_value,2的31次方,20多億

 

threadpoolexecutor服務類bean生命週期,construct構造線程池對象,init初始化--無,destroy--shutdown()

 

 

 

 

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章