Impossible to make a cached thread pool with a size limit?

前端 未结 13 870
日久生厌
日久生厌 2020-11-28 00:31

It seems to be impossible to make a cached thread pool with a limit to the number of threads that it can create.

Here is how static Executors.newCachedThreadPool is

13条回答
  •  误落风尘
    2020-11-28 01:26

    Per the Javadoc for ThreadPoolExecutor:

    If there are more than corePoolSize but less than maximumPoolSize threads running, a new thread will be created only if the queue is full. By setting corePoolSize and maximumPoolSize the same, you create a fixed-size thread pool.

    (Emphasis mine.)

    jitter's answer is what you want, although mine answers your other question. :)

提交回复
热议问题