Core pool size vs maximum pool size in ThreadPoolExecutor

后端 未结 10 1042
滥情空心
滥情空心 2020-11-29 16:08

What exactly is the difference between core pool size and maximum pool size when we talk in terms of ThreadPoolExecutor?
C

10条回答
  •  失恋的感觉
    2020-11-29 16:53

    From the doc:

    When a new task is submitted in method execute(java.lang.Runnable), and fewer than corePoolSize threads are running, a new thread is created to handle the request, even if other worker threads are idle. If there are more than corePoolSize but less than maximumPoolSize threads running, a new thread will be created only if the queue is full.

    Furthermore:

    By setting corePoolSize and maximumPoolSize the same, you create a fixed-size thread pool. By setting maximumPoolSize to an essentially unbounded value such as Integer.MAX_VALUE, you allow the pool to accommodate an arbitrary number of concurrent tasks. Most typically, core and maximum pool sizes are set only upon construction, but they may also be changed dynamically using setCorePoolSize(int) and setMaximumPoolSize(int).

提交回复
热议问题