美文网首页
使用MapReduce计算小案例优化(一)

使用MapReduce计算小案例优化(一)

作者: 神豪VS勇士赢 | 来源:发表于2020-07-22 22:11 被阅读0次

上篇文章中 我们实现了一个简单的MapReduce计算的小案例 但是也存在很多痛点

再次运行java jar xxxx 报异常 原因很简单就是因为我们输出路径文件已经有了 这个时候需要重新指定新的输出路径,或者删除掉上次输出的文件 。

可以在 Java 代码做优化 或者写一个 shell 脚本做优化 。

1)脚本如下:
即先删除原来路径文件 再再次运行


image.png

2)
代码优化如下:
在main 方法中加入 判断

        Path path = new Path(args[1]);
        FileSystem fileSystem = FileSystem.get(configuration);
        if (fileSystem.exists(path)) {
            fileSystem.delete(path, true);
            System.out.println("output file  delete success ");
        }

相关文章

网友评论

      本文标题:使用MapReduce计算小案例优化(一)

      本文链接:https://www.haomeiwen.com/subject/iwhxlktx.html