Home | About | Sematext search-lucene.com search-hadoop.com
NEW: Monitor These Apps!
elasticsearch, apache solr, apache hbase, hadoop, redis, casssandra, amazon cloudwatch, mysql, memcached, apache kafka, apache zookeeper, apache storm, ubuntu, centOS, red hat, debian, puppet labs, java, senseiDB
 Search Hadoop and all its subprojects:

Switch to Threaded View
HDFS >> mail # user >> Static class vs Normal Class when to use


Copy link to this message
-
Re: Static class vs Normal Class when to use
Another Ted piping in.

For Hadoop use, it is dangerous to use anything but a static class for your
mapper and reducer functions since you may accidentally think that you can
access a closed variable from the parent.  A static class cannot reference
those values so you know that you haven't made that mistake.  If the mapper
or reducer class is not embedded in another class (i.e. not a member class)
then it is automatically static since there is nothing to inherit from.

Contrarily, static members in the mapper or reducer are real trouble unless
they are static final.  The problem is that different mapper and reducer
invocations will see different values of these static values because they
are running in different JVM's.  Dependence on statics is a common
beginner's mistake in Hadoop.

On Thu, Mar 28, 2013 at 6:01 AM, Sai Sai <[EMAIL PROTECTED]> wrote:

> Hi Ted
> Thanks for your help it is really appreciated.
> I have gone thru the links that you have provided but i am looking for a
> simple exaplanation of using static classes in Hadoop/MR while
> syntactically i know how the static classes and variables r referred, i am
> wondering if there was something more than that we use static classes.
> In other words assuming static classes r loaded at the time the classes r
> loaded and not at the time the object is created and the timespan of
> objects of static classes r less than normal classes. Please let me know if
> this make sense and provide any additional info if you could.
> Thanks again.
> Sai
>
>
>   ------------------------------
> *From:* Ted Yu <[EMAIL PROTECTED]>
> *To:* [EMAIL PROTECTED]; Sai Sai <[EMAIL PROTECTED]>
> *Sent:* Thursday, 28 March 2013 9:41 AM
> *Subject:* Re: Static class vs Normal Class when to use
>
> Take a look at Effective Java 2nd edition:
>  Item 22: Favor static member classes over nonstatic
>
> On Wed, Mar 27, 2013 at 9:05 PM, Ted Yu <[EMAIL PROTECTED]> wrote:
>
> See
> http://stackoverflow.com/questions/1353309/java-static-vs-non-static-inner-class
>
> I believe Josh Bloch covers this in his famous book.
>
>
> On Wed, Mar 27, 2013 at 9:01 PM, Sai Sai <[EMAIL PROTECTED]> wrote:
>
> In some examples/articles sometimes they use:
> public static class MyMapper
>
> and sometimes they use
>
> public class MyMapper
>
> When/why should we use static vs normal class.
>
> Thanks
> Sai
>
>
>
>
>
>
NEW: Monitor These Apps!
elasticsearch, apache solr, apache hbase, hadoop, redis, casssandra, amazon cloudwatch, mysql, memcached, apache kafka, apache zookeeper, apache storm, ubuntu, centOS, red hat, debian, puppet labs, java, senseiDB