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