<address id="ousso"></address>
<form id="ousso"><track id="ousso"><big id="ousso"></big></track></form>
  1. Java自定義線程池相關代碼

    時間:2024-09-14 08:50:08 SUN認證 我要投稿
    • 相關推薦

    Java自定義線程池相關代碼

      創建Java自定義線程池的構造方法很多,但是我們在使用中就會有以下幾個最主要的代碼應用。我們在使用的時候就要先來了解下有關Java自定義線程池的源代碼。本例中參數的含義如下:

      Java代碼

      1.ThreadPoolExecutor

      2.public ThreadPoolExecutor(int corePoolSize,

      3.int maximumPoolSize,

      4.long keepAliveTime,

      5.TimeUnit unit,

      6.BlockingQueue workQueue)

      用給定的初始參數和默認的線程工廠及處理程序創建新的 ThreadPoolExecutor。使用 Executors 工廠方法之一比使用此通用構造方法方便得多。

      參數:

      7.corePoolSize - 池中所保存的線程數,包括空閑線程。

      8.maximumPoolSize - 池中允許的最大線程數。

      9.keepAliveTime - 當線程數大于核心時,此為終止前多余的空閑線程

      等待新任務的最長時間。

      10.unit - keepAliveTime 參數的時間單位。

      11.workQueue - 執行前用于保持任務的隊列。此隊列僅保持由 execute

      方法提交的 Runnable 任務。

      拋出:

      IllegalArgumentException - 如果 corePoolSize 或 keepAliveTime 小于零,或者 maximumPoolSize 小于或等于零,或者 corePoolSize 大于 maximumPoolSize。

      NullPointerException - 如果 workQueue 為 null

      12.ThreadPoolExecutor

      13.public ThreadPoolExecutor(int corePoolSize,

      14.int maximumPoolSize,

      15.long keepAliveTime,

      16.TimeUnit unit,

      17.BlockingQueue workQueue)

      用給定的初始參數和默認的線程工廠及處理程序創建新的 ThreadPoolExecutor。使用 Executors 工廠方法之一比使用此通用構造方法方便得多。

      參數:

      18.corePoolSize - 池中所保存的線程數,包括空閑線程。

      19.maximumPoolSize - 池中允許的最大線程數。

      20.keepAliveTime - 當線程數大于核心時,此為終止前多余的空閑

      線程等待新任務的最長時間。

      21.unit - keepAliveTime 參數的時間單位。

      22.workQueue - 執行前用于保持任務的隊列。此隊列僅保持由 execute

      方法提交的 Runnable 任務。

      23.拋出:

      24.IllegalArgumentException - 如果 corePoolSize 或

      keepAliveTime 小于零,或者 maximumPoolSize 小于或等于零,

      或者 corePoolSize 大于 maximumPoolSize。

      25.NullPointerException - 如果 workQueue 為 null

      Java自定義線程池稍微麻煩些,不過通過創建的ThreadPoolExecutor線程池對象,可以獲取到當前線程池的尺寸、正在執行任務的線程數、工作隊列等等。

    【Java自定義線程池相關代碼】相關文章:

    Java線程同步的方法10-25

    Java多線程的實現方式07-08

    在Java中執行JavaScript代碼07-14

    如何讓JAVA代碼更高效07-18

    java證書的加密與解密代碼06-12

    Java中的動態代碼編程06-27

    Java代碼的基本知識10-26

    java多線程面試題201710-03

    關于Java源代碼折行的規則10-27

    java非對稱加密的源代碼(rsa)08-01

    <address id="ousso"></address>
    <form id="ousso"><track id="ousso"><big id="ousso"></big></track></form>
    1. 日日做夜狠狠爱欧美黑人