zoukankan      html  css  js  c++  java
  • 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()); 
     }
    }

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

    求教如何使mapper和reducer能共享变量?

  • 相关阅读:
    HDU
    HDU
    (4)数据--相似性与相异性
    (3)数据--操作
    (2)数据--基本概念
    五、按生命周期划分数据(二)
    五、常用数据类型(一)
    四、坏耦合的原因与解耦(三)
    四、强化耦合(二)
    四、初识耦合(一)
  • 原文地址:https://www.cnblogs.com/children/p/1935913.html
Copyright © 2011-2022 走看看