2017-01-17 80 views
2

什麼是使用簡單的job.waitForCompletion(true)方法,並通過ToolRunner.run(新MyClass的(),參數)開始映射減少的Apache Hadoop的工作有什麼區別?不同的方式MapReduce工作

我有以下兩種方式執行的MapReduce工作:

首先如下:

public class MaxTemperature extends Configured implements Tool { 
    public static void main(String[] args) throws Exception { 
     int exitCode = ToolRunner.run(new MaxTemperature(), args); 
     System.exit(exitCode); 
    } 

    @Override 
    public int run(String[] args) throws Exception { 
     if (args.length != 2) { 
       System.err.println("Usage: MaxTemperature <input path> <output path>"); 
       System.exit(-1); 
      } 
     System.out.println("Starting job"); 
     Job job = new Job(); 
     job.setJarByClass(MaxTemperature.class); 
     job.setJobName("Max temperature"); 

     FileInputFormat.addInputPath(job, new Path(args[0])); 
     FileOutputFormat.setOutputPath(job, new Path(args[1])); 

     job.setMapperClass(MaxTemperatureMapper.class); 
     job.setReducerClass(MaxTemperatureReducer.class); 

     job.setOutputKeyClass(Text.class); 
     job.setOutputValueClass(IntWritable.class); 
     int returnValue = job.waitForCompletion(true) ? 0:1; 

     if(job.isSuccessful()) { 
      System.out.println("Job was successful"); 
     } else if(!job.isSuccessful()) { 
      System.out.println("Job was not successful");   
     } 
     return returnValue; 
    } 
} 

其次爲:

public class MaxTemperature{ 

    public static void main(String[] args) throws Exception { 

     if (args.length != 2) { 
       System.err.println("Usage: MaxTemperature <input path> <output path>"); 
       System.exit(-1); 
      } 
     System.out.println("Starting job"); 
     Job job = new Job(); 
     job.setJarByClass(MaxTemperature.class); 
     job.setJobName("Max temperature"); 

     FileInputFormat.addInputPath(job, new Path(args[0])); 
     FileOutputFormat.setOutputPath(job, new Path(args[1])); 

     job.setMapperClass(MaxTemperatureMapper.class); 
     job.setReducerClass(MaxTemperatureReducer.class); 

     job.setOutputKeyClass(Text.class); 
     job.setOutputValueClass(IntWritable.class); 
     int returnValue = job.waitForCompletion(true) ? 0:1; 

     if(job.isSuccessful()) { 
      System.out.println("Job was successful"); 
     } else if(!job.isSuccessful()) { 
      System.out.println("Job was not successful"); 

    } 
} 

來自兩個方面的輸出是一樣的。但我沒有得到兩者之間的區別? 哪一個比另一個更受歡迎?

回答

0

這篇文章做了解釋使用ToolRunner的一個相當體面的工作:ToolRunner

+0

請,避免鏈路只有答案。相反,在這裏嘗試提供答案的基礎知識,然後提供鏈接瞭解更多詳情。如果鏈接無效,您的答案也會如此 – vefthym

相關問題