ThreadPoolExecutor and the queue

前端 未结 2 519
遇见更好的自我
遇见更好的自我 2021-02-06 11:18

I thought that using ThreadPoolExecutor we can submit Runnables to be executed either in the BlockingQueue passed in the constructor or using the

2条回答
  •  谎友^
    谎友^ (楼主)
    2021-02-06 12:03

    A BlockingQueue is not a magic thread dispatcher. If you submit Runnable objects to the queue and there are no running threads to consume those tasks, they of course will not be executed. The execute method on the other hand will automatically dispatch threads according to the thread pool configuration if it needs to. If you pre-start all of the core threads, there will be threads there to consume tasks from the queue.

提交回复
热议问题