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能共享变量?
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能共享变量?
相关文章推荐
- VLC各个Module模块之间如何共享变量
- Hadoop基于WordCount的Mapper、Reducer、Combiner、Partitioner和自定义多文件输出
- hadoop学习-Mapper和Reducer的输出类型
- hadoop中map/reduce编程中关于mapper和reducer的Format问题
- Hadoop-2.4.1学习之如何确定Mapper数量
- 线程不安全的类不要轻易做为static变量使用,及如何使用ThreadLocal将共享变量变为独享变量
- jenkins中如何实现执行脚本时的变量共享
- Hadoop-Mapper-Reducer文档学习
- 在一个程序中需要用到全局变量(在多个class之间共享数据),请问如何定义具有这种功能的变量?或者是否有其他的方法解决多个class之间的数据共享(尽量简单实现)。 首先应该明确 Java中没有全局变
- 关于全局变量,如何被多个.c文件共享问题
- 提高hadoop的mapreduce job效率笔记之一(修改mapper和reducer数量)
- hadoop mapper reducer sample demo
- 不同类如何共享同一个变量
- KVM如何以HADOOP作共享存储?
- angular如何实现不同模块的变量共享
- 多个C程序如何访问(共享)同一变量(数据)?
- Hadoop中map/reduce编程中关于mapper和reducer的Format问题
- tensorflow里面共享变量、name_scope, variable_scope等如何理解
- hadoop 多个Mapper和Reducer的Job
- Hadoop-2.4.1学习之Mapper和Reducer