您的位置:首页 > 移动开发

Hadoop的Mapper和Reducer如何共享变量

2011-01-14 20:57 399 查看
代码

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());
}
}

虽然编译成功,但在main中的输出显示,map为null。

求教如何使mapper和reducer能共享变量?
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: