关于Tool接口--------hadoop接口:extends Configured implements Tool 和 ToolRunner.run

  我们在写Hadoop--map/reduce程序时,遇到使用按文件url来分析文件----------多表连接的DistributedCache方式,看不懂使用extends Configured implements Tool的方式,就查了一下http://hadoop.apache.org      上面对该Tool接口及其使用做了说明:

  1. @InterfaceAudience.Public  
  2. @InterfaceStability.Stable  
  3. public interface Tool       //Tool接口继承了Configurable  
  4. extends Configurable  
  5. //Tool接口可以支持处理通用的命令行选项,它是所有Map-Reduce程序的都可用的一个标准接口,下面是一个典型用例:  
  6.   
  7.          public class MyApp extends Configured implements Tool {  
  8.            
  9.            public int run(String[] args) throws Exception {  
  10.              //ToolRunner要处理的Configuration,Tool通过ToolRunner调用ToolRunner.run时,传入参数Configuration  
  11.              Configuration conf = getConf();  
  12.                
  13.              JobConf job = new JobConf(conf, MyApp.class);  
  14.                
  15.              Path in = new Path(args[1]);  
  16.              Path out = new Path(args[2]);  
  17.                
  18.              // 设置job的各种详细参数      
  19.              job.setJobName("my-app");  
  20.              job.setInputPath(in);  
  21.              job.setOutputPath(out);  
  22.              job.setMapperClass(MyMapper.class);  
  23.              job.setReducerClass(MyReducer.class);  
  24.   
  25.              //提交job  
  26.              JobClient.runJob(job);  
  27.              return 0;  
  28.            }  
  29.              
  30.            public static void main(String[] args) throws Exception {  
  31.              // 让ToolRunner执行   
  32.              int res = ToolRunner.run(new Configuration(), new MyApp(), args);  
  33.                
  34.              System.exit(res);  
  35.            }  
  36.          }  

原文地址:https://www.cnblogs.com/zlslch/p/6431833.html