我有一个类(为了便于阅读,我删除了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));
}
}
Run Code Online (Sandbox Code Playgroud)
在我的程序中,我是第一个HadoopFileSysem对象,我不关闭它.
然后我创建了第二个HadoopFileSysem对象,然后关闭它.
最后,当我想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"); // …Run Code Online (Sandbox Code Playgroud)