ThreadPoolExecutor和ArrayBlockingQueue

时间:2015-01-18 16:55:42

标签: runnable java.util.concurrent callable threadpoolexecutor

请原谅我的英语不好。 当池中的线程数增加到10以上时,该任务将被放置在ArrayBlockingQueue中。但如果任务可以调用?构造函数ThreadPoolExecutor不接受类型为Callable的ArrayBlockingQueue。那么,如何将任务添加到队列中?

ExecutorService executorService = new ThreadPoolExecutor(2, 10,
                60L, TimeUnit.SECONDS,
                new ArrayBlockingQueue<Runnable>(100));

1 个答案:

答案 0 :(得分:0)

ThreadPoolExecutor不会直接将Callable添加到队列中。相反,它会将Callable打包成RunnableFuture 通过调用方法AbstractExecutorService.newTaskFor(Callable),然后将此RunnableFuture添加到队列中。