hadoop框架
wordcount mr java代码
1 public class WordCount { 2 public static class Map{ 3 static IntWritable one = new IntWritable(1); 4 Text word = new Text(); 5 public void map(Object key, Text values, Context context) throws IOException, InterruptrdException{ 6 StringTokenzier str = new StringTokenzier(values); 7 while (str.hasMoreToken()) { 8 word.set(str.nextToken()); 9 context.write(word, one); 10 } 11 } 12 } 13 public static class Reduce{ 14 static IntWritable ans = new IntWritable(); 15 public void reduce(Text key, Iterator<IntWritable> values, Context context) throws IOException, InterruptedException { 16 int sum = 0; 17 while (values.hasNext()) { 18 sum += values.getNext(); 19 } 20 ans.set(sum); 21 Conetxt.write(key, ans); 22 } 23 } 24 }
hadoop优化的七个建议 http://langyu.iteye.com/blog/916304