Tag: 执行程序

当队列满时ThreadPoolExecutor块?

我正在尝试使用ThreadPoolExecutor执行大量的任务。 以下是一个假设的例子: def workQueue = new ArrayBlockingQueue<Runnable>(3, false) def threadPoolExecutor = new ThreadPoolExecutor(3, 3, 1L, TimeUnit.HOURS, workQueue) for(int i = 0; i < 100000; i++) threadPoolExecutor.execute(runnable) 问题是我很快得到java.util.concurrent.RejectedExecutionException,因为任务的数量超过了工作队列的大小。 但是,我期望的行为是让主线程阻塞,直到队列中有空间。 什么是完成这个最好的方法?

什么时候应该使用Java的Thread over Executor?

执行者似乎是一个干净的抽象。 你想什么时候直接使用Thread而不是依赖更强大的执行器?