我需要向Hadoop提交几个相关的作业(这就是为什么它们是由同一驱动程序类启动的),但是彼此完全独立。现在我开始这样的工作:

int res = ToolRunner.run(new Configuration(), new MapReduceClass(params), args);

运行作业,获取返回代码,然后继续。

我想做的是提交几个并行运行的作业,以获取每个作业的返回码。

(对我而言)一个显而易见的想法是启动多个线程,每个线程负责一个hadoop作业,但是我想知道hadoop是否有更好的方法来完成此任务?我没有任何编写并发代码的经验,所以除非有必要,否则我不愿意花费很多时间来学习它的复杂性。

最佳答案

这可能是一个建议,但暗含了代码,因此我将其作为答案。

在此代码(个人代码)中,我只是遍历一些变量,然后多次提交一份工作(同一份工作)。

使用job.waitForCompletion(false)将帮助您提交多个作业。

while (processedInputPaths < inputPaths.length) {

    if (processedInputPaths + inputPathsLimit < inputPaths.length) {
        end = processedInputPaths + inputPathsLimit - 1;
    } else {
        end = inputPaths.length - 1;
    }
    start = processedInputPaths;

    Job job = this.createJob(configuration, inputPaths, cycle, start, end, outputPath + "/" + cycle);

    boolean success = job.waitForCompletion(true);

    if (success) {
        cycle++;
        processedInputPaths = end + 1;
    } else {
        LOG.info("Cycle did not end successfully :" + cycle);
        return -1;
    }

}

09-10 01:04
查看更多