我想我的代码中有线程泄漏,但我不知道为什么。这是代码 -
foo(String solutionFileName, String SubmissionFileName){
ExecutorService e = Executors.newFixedThreadPool(
Future<BufferedReader> f1 = e.submit(new Builder(solutionFileName));
Future<BufferedReader> f2 = e.submit(new Builder(submissionFileName));
BufferedReader b1=f1.get();
BufferedReader b2=f2.get();
//do a little work
e.shutdown();
}
class Builder{
Builder(String fileName){this.fileName=fileName;}
public BufferedReader call() throws FileNotFoundException{
return new BufferedReader(new InputStreamReader(new FileInputStream(fileName)));
String fileName;
}
}
我在 Eclipse 上运行它,问题是当我遇到 FileNotFoundException 时,JVM 并没有死。我必须手动终止它。我不明白为什么...