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能共享变量?

  • 相关阅读:
    大规模机器学习
    机器学习之推荐系统
    SVM实现邮件分类
    机器学习之异常检测
    降维算法学习
    手写数字识别实现
    动态规划训练之十七
    概率期望训练之三
    数据结构训练之四
    绵阳东辰国际test201910.25
  • 原文地址:https://www.cnblogs.com/children/p/1935913.html
Copyright © 2011-2022 走看看