【发布时间】:2017-04-28 02:51:29
【问题描述】:
线程池在提交时拒绝任务。线程池大小是固定的,它是 8。即使我没有提交超过 8 个的任务,它也会被拒绝。我尝试使用阻塞队列,但它对我没有帮助。
这是我的代码 sn-p
try {
List<Future> tasks = new ArrayList<Future>();
ThreadPoolExecutor tpe = (ThreadPoolExecutor) Executors.newFixedThreadPool(10);
Process process = new Process();
ProcessingJobMeta meta = process.getPJM();
List<CuratedInput> cil = meta.getCuratedInputList();
for (final CuratedInput ci : cil) {
for (final Preperation prep : Preperation.values()) {
for (final Export export : Export.values()) {
Runnable runnable = new Runnable() {
public void run() {
LOGGER.info("Executing.................." + prep.toString() );
LOGGER.info("Executing.................." + export.toString());
PreperationFactory.getPreperation(prep.toString(), ci);
ExportFactory.getExport(export.toString(), ci);
}
};
// tpe.submit(runnable);
tasks.add((Future) tpe.submit(runnable));
for (Future p : tasks) {
LOGGER.info("---------------inside the futures for loop------------");
LOGGER.info("Result of the future executed ------> " + p.get());
}
tpe.shutdown();
while (!tpe.isShutdown()) {
}
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
【问题讨论】:
标签: java threadpool threadpoolexecutor