一:说明
1.说明
String的操作特别消耗内存,所以可以考虑优化。
二:程序
1.程序修改
这部分程序属于Mapper端的程序,稍微优化一下。
2.程序
//Mapper
public static class WordCountMapper extends Mapper<LongWritable,Text,Text,IntWritable>{
private Text mapoutputkey=new Text();
private static final IntWritable mapoutputvalue=new IntWritable(1);
@Override
protected void map(LongWritable key, Text value, Context context)throws IOException, InterruptedException {
String lineValue=value.toString();
StringTokenizer stringTokenizer =new StringTokenizer(lineValue);
while(stringTokenizer.hasMoreTokens()){
mapoutputkey.set(stringTokenizer.nextToken());
context.write(mapoutputkey, mapoutputvalue);
}
} }