title: Accessing a static HashMap outside mapper/reducer classes in mapreduce
body: <p>I’m trying to write a mapreduce program where the map function adds items to a HashMap, and the reducer then accesses those items and writes it to output. </p>
  
  <pre><code>public class MyClass {
      static HashMap&lt;String, Integer&gt; temp = new HashMap&lt;String, Integer&gt;();
  
      public static class Map1 extends Mapper&lt;LongWritable, Text, Text, IntWritable&gt; {
          public void map(LongWritable key, Text value, Context context) {
              temp.put("1", 1);
          }
      }
  
      public static class Reduce1 extends Reducer&lt;Text, IntWritable, Text, Text&gt; {
  
          @Override
          public void reduce(Text key, Iterable&lt;IntWritable&gt; values, Context context) {
              Iterator it = temp.entrySet().iterator();
              while (it.hasNext()) {
                  Map.Entry&lt;String, Integer&gt; pair = (Map.Entry&lt;String, Integer&gt;)it.next();
                  String key = pair.getKey();
                  String val = Integer.toString(pair.getValue());
                  context.write(new Text(key), new Text(val));
              }
          }
      }
  </code></pre>
  
  <p>This compiles fine, but the output from the reducer is empty. I'm not great at Java, so i'm not quite sure what's going wrong here.</p>