我有一个类(为了可读性,我去掉了try/catch):
public class HadoopFileSystem {
private FileSystem m_fileSystem = null;
public HadoopFileSystem() {
Configuration l_configuration = new Configuration();
l_configuration .set("fs.default.name", "hdfs://localhost:9100");
l_configuration .set("mapred.job.tracker", "localhost:9101");
m_fileSystem = FileSystem.get(l_configuration );
}
public void close() {
m_fileSystem.close();
}
public void createFile(String a_pathDFS) {
m_fileSystem.create(new Path(a_pathDFS));
}
}
在我的程序中,我首先创建了一个
HadoopFileSystem
对象,但我没有关闭它。然后我创建了第二个HadoopFileSystem
对象,并将其关闭。最后,当我想在第一个对象上使用m_fileSystem
的函数时,我会遇到错误:java.io.IOException: Filesystem closed
。但我没有关闭它!以下是一些代码来说明我的问题:HadoopFileSystem h1 = new HadoopFileSystem();
HadoopFileSystem h2 = new HadoopFileSystem();
if(h1 == h2)
System.out.println("=="); // No print
if(h1.equals(h2))
System.out.println("equals"); // No print
h2.close();
h1.createFile("test.test"); // ERROR : java.io.IOException: Filesystem closed
h1.close();
为什么?