多个Hadoop FileSystem实例 [英] Multiples Hadoop FileSystem instances
问题描述
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(==); //不打印
if(h1.equals(h2))
System.out.println(equals); //没有打印
h2.close();
h1.createFile(test.test); //错误:java.io.IOException:文件系统关闭
h1.close();
为什么?
m_fileSystem = FileSystem.get(l_configuration);
是一个静态调用,即使您创建了两个不同的对象。你需要找到一种方法来不使这个调用对于两个不同的对象是静态的。
试着解决这个问题, / p>
conf.setBoolean(fs.hdfs.impl.disable.cache,true);
I have a class (I removes try/catch for readability):
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));
}
}
In my program, I a first HadoopFileSysem
object, I don't close it.
Then I create a second HadoopFileSysem
object, and I close it.
Finally, when I want to use a function on m_fileSystem
in my first object, I have the error : java.io.IOException: Filesystem closed
But I did'nt close it !
Here's a little code to illustrate my problem :
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 );
is a static call even if you have two different objects created. You need to find a way to not make this call static for two different objects.
Try this out to do away with the problem,
conf.setBoolean("fs.hdfs.impl.disable.cache", true);
这篇关于多个Hadoop FileSystem实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!