码迷,mamicode.com
首页 > 其他好文 > 详细

WordCount深入分析------JobClient学习

时间:2015-10-31 17:02:42      阅读:188      评论:0      收藏:0      [点我收藏+]

标签:

public static void main(String[] args) throws Exception {
Configuration conf = new Configuration();
//conf就是作业的配置对象,读取core-site、core-default、hdfs-site/default、mapred-site/default文件里的配置信息    	
 String[] otherArgs = new GenericOptionsParser(conf, args).getRemainingArgs();
//args[]就是使用hadoop jar命令运行作业时输入/输出路径参数,这两个参数传给了main函数
    if (otherArgs.length != 2) {
      System.err.println("Usage: wordcount <in> <out>");
      System.exit(2);//System.exit(0)表示正常退出,exit()参数非0表示非正常退出。
    }

    Job job = new Job(conf, "word count");    
//以下就是设置job的一些运行参数,这些方法内部都会调用jobconf对象对应的方法
    job.setJarByClass(WordCount.class);
    job.setMapperClass(TokenizerMapper.class);
    job.setCombinerClass(IntSumReducer.class);
    job.setReducerClass(IntSumReducer.class);
    job.setOutputKeyClass(Text.class);
    job.setOutputValueClass(IntWritable.class);
//以下就是设置job的一些运行参数,这些方法内部都会调用jobconf对象对应的方法
    FileInputFormat.addInputPath(job, new Path(otherArgs[0]));
    FileOutputFormat.setOutputPath(job, new Path(otherArgs[1]));
    System.exit(job.waitForCompletion(true) ? 0 : 1);
}

  

WordCount深入分析------JobClient学习

标签:

原文地址:http://www.cnblogs.com/lz3018/p/4925758.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!