Hadoop的Mapper和Reducer如何共享变量
代码
public class ShortestPath {
static Map<String, Integer> map=new HashMap<String, Integer>();
public static class TokenizerMapper extends Mapper<LongWritable, Text, Text, Text> {
public void map(LongWritable key, Text value, Context context)
throws IOException, InterruptedException {
map.put("test",123");
}
}
public static class ShortestPathReducer extends Reducer<Text, Text, Text, Text> {
public void reduce(Text key, Iterable<Text> values, Context context)
throws IOException, InterruptedException {
map.put("test",123");
}
}
public static void main(String[] args) throws Exception {
System.out.println(map.toString());
static Map<String, Integer> map=new HashMap<String, Integer>();
public static class TokenizerMapper extends Mapper<LongWritable, Text, Text, Text> {
public void map(LongWritable key, Text value, Context context)
throws IOException, InterruptedException {
map.put("test",123");
}
}
public static class ShortestPathReducer extends Reducer<Text, Text, Text, Text> {
public void reduce(Text key, Iterable<Text> values, Context context)
throws IOException, InterruptedException {
map.put("test",123");
}
}
public static void main(String[] args) throws Exception {
System.out.println(map.toString());
}
}
}
虽然编译成功,但在main中的输出显示,map为null。
求教如何使mapper和reducer能共享变量?