【发布时间】:2013-07-02 08:47:46
【问题描述】:
我有一个类(为了便于阅读,我删除了 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));
}
}
在我的程序中,我是第一个 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"); // No print
h2.close();
h1.createFile("test.test"); // ERROR : java.io.IOException: Filesystem closed
h1.close();
为什么?
【问题讨论】:
-
您能否将代码发布在您创建 HadoopFileSystems 的位置以及调用函数的位置?此类不太可能包含您要查找的错误
-
我刚刚用我的示例进行了编辑