hadoop-common-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From madhu phatak <phatak....@gmail.com>
Subject Very strange Java Collection behavior in Hadoop
Date Tue, 20 Mar 2012 05:52:47 GMT
Hi All,
 I am using Hadoop 0.20.2 . I am observing a Strange behavior of Java
Collection's . I have following code in reducer

       public void reduce(Text text, Iterator<Text> values,
            OutputCollector<Text, Text> collector, Reporter reporter)
throws IOException {
        // TODO Auto-generated method stub
        List<Text> list = new ArrayList<Text>();
        while(values.hasNext())
        {
            Text value = values.next();
            list.add(value);
            System.out.println(value.toString());       }

        for(Text value : list)
        {
            System.out.println(value.toString());
        }

    }

The  first sysout prints following

4       5       6

1	2	3

But when I print from the List, it prints following

1	2	3
1	2	3

*
*The all List values are getting replaced by last added value.

I am not able to understand this behavior. Did anyone seen this behavior ?

Regards,
Madhukara Phatak

-- 
https://github.com/zinnia-phatak-dev/Nectar

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message