Why doesn't ScheduledExecutorService spawn threads as needed?

前端 未结 2 778
心在旅途
心在旅途 2021-01-04 18:16

In my application I use ScheduledExecutorService, but only one thread is spawned to handle the scheduled tasks. Is this because ScheduledExecutorService does not spawn thre

2条回答
  •  借酒劲吻你
    2021-01-04 18:54

    There is only one thread because you create the thread pool with Executors.newScheduledThreadPool(1), which means that the thread pool contains only 1 thread. If you want 10 threads, pass 10 as argument. Note that the documentation of ScheduledThreadPoolExecutor, which is what this method returns, explicitly says that the thread pool has a fixed size.

提交回复
热议问题