You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-user@hadoop.apache.org by ma qiang <ma...@gmail.com> on 2008/03/16 06:35:26 UTC

why the value of attribute in map function will change ?

Hi all:
    I have this map class as below;
    public class TestMap extends MapReduceBase implements Mapper
    {
          private static int value;

          public TestMap()
          {
               value=100;
          }

          public void map……

         ……………………
    }

 and in my Driver Class as below:
   public class Driver {
	
	public void main() throws Exception {
                conf……………………………	
		
		client.setConf(conf);
		try {	
			JobClient.runJob(conf);
		} catch (Exception e) {
			e.printStackTrace();
		}
	
                System.out.println(TestMap.value);     //here the
value printed is 0;
	}

I don't know why the TestMap.value printed is not 100 but 0, who can
tell me why ?
Thanks very much!

RE: why the value of attribute in map function will change ?

Posted by Jeff Eastman <je...@windwardsolutions.com>.
Consider that your mapper and driver execute in different JVMs and cannot
share static values.

Jeff

> -----Original Message-----
> From: ma qiang [mailto:maqiang1984@gmail.com]
> Sent: Saturday, March 15, 2008 10:35 PM
> To: core-user@hadoop.apache.org
> Subject: why the value of attribute in map function will change ?
> 
> Hi all:
>     I have this map class as below;
>     public class TestMap extends MapReduceBase implements Mapper
>     {
>           private static int value;
> 
>           public TestMap()
>           {
>                value=100;
>           }
> 
>           public void map..
> 
>          ........
>     }
> 
>  and in my Driver Class as below:
>    public class Driver {
> 
> 	public void main() throws Exception {
>                 conf...........
> 
> 		client.setConf(conf);
> 		try {
> 			JobClient.runJob(conf);
> 		} catch (Exception e) {
> 			e.printStackTrace();
> 		}
> 
>                 System.out.println(TestMap.value);     //here the
> value printed is 0;
> 	}
> 
> I don't know why the TestMap.value printed is not 100 but 0, who can
> tell me why ?
> Thanks very much!