我们可以在定义 ThreadPoolExecutors 时提供 BlockingQueue 实现。但是,如果我使用工厂(执行器)创建单个线程池(如下所示),我想知道使用哪个阻塞队列。我猜它是一个 LinkedBlockingQueue。文档讨论了无界队列,但没有透露实现。
ExectorService service = Executors.newSingleThreadExecutor();
最佳答案
这是来自 Executors src:
public static ExecutorService newSingleThreadExecutor() {
return new FinalizableDelegatedExecutorService
(new ThreadPoolExecutor(1, 1,
0L, TimeUnit.MILLISECONDS,
new LinkedBlockingQueue<Runnable>()));
}
关于java - Executor 内部的数据结构,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27486163/