How does maximumPoolSize of ThreadPoolExecutor works?

后端 未结 3 828
渐次进展
渐次进展 2021-01-12 03:05

I\'m trying to understand ThreadPoolExecutor class. I have read this answer and the Javadoc. But my experimentation doesn\'t match with that description:

I initializ

3条回答
  •  旧时难觅i
    2021-01-12 03:22

    From the API 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.

    Your queue never fills since it has a capacity of 1000. If you change the capacity to 1, you will see Threads being created.

    The Executors class uses a SynchronousQueue for its newCachedThreadPool methods, so you might want to consider using it as well.

提交回复
热议问题