我有一个类(为了便于阅读,我删除了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();

为什么呢

最佳答案

即使您创建了两个不同的对象,m_fileSystem = FileSystem.get(l_configuration );也是一个静态调用。您需要找到一种方法而不是来使两个不同对象的调用变为静态。

尝试解决该问题,

conf.setBoolean("fs.hdfs.impl.disable.cache", true);

08-19 09:30