In Hadoop word count example IntWritable is made static so that it can be reused in the same JVM instead of creating new. My question is why not make text also static?
I made it and is working fine but never saw that in any example. Am I missing something?
private ***static*** Text word = new Text();
private final static IntWritable intWritable = new IntWritable(1);
The original word count example.
public static class Map extends MapReduceBase implements Mapper<LongWritable, Text, Text, IntWritable> {
private final static IntWritable one = new IntWritable(1);
private Text word = new Text();
public void map(LongWritable key, Text value, OutputCollector<Text, IntWritable> output, Reporter reporter) throws IOException {
String line = value.toString();
StringTokenizer tokenizer = new StringTokenizer(line);
while (tokenizer.hasMoreTokens()) {
word.set(tokenizer.nextToken());
output.collect(word, one);
}
}