我有一堂课(为了便于阅读,我删除了 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();
Why ?
m_fileSystem = FileSystem.get(l_configuration );
即使您创建了两个不同的对象,也是静态调用。你需要找到一种方法not使此调用对于两个不同的对象是静态的。
尝试一下这个方法来解决这个问题
conf.setBoolean("fs.hdfs.impl.disable.cache", true);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)