我ExecutorService
用来生成线程来执行不同的任务。当submit(Callable<T>)
方法被创建时,它应该返回一个Future<T>
对象。相反,它返回 null。结果,当Future<T>.get()
调用方法时,它将失败并显示NullPointerException
.
有没有人遇到过这个问题?或者,我做错了什么?
ArrayList<Boolean> resultsList = new ArrayList<Boolean> ();
ExecutorService excutorService = Executors.newCachedThreadPool();
for(ClassImplementingCallable myClassImplementingCallable : listOfClassesImplementingCallable) {
resultsList.add( excutorService.submit( myClassImplementingCallable ) );
}
excutorService.shutdown();
for ( Future< Boolean > result : resultList ) {
result.get(); // getting exception here..
}