river-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Gregg Wonderly <gr...@wonderly.org>
Subject Re: Bad idiom
Date Tue, 08 Feb 2011 15:00:02 GMT
I think that there is a case either way.  Some designs may, in fact want 
subclasses to share separate counters.  Using the explicit MyClassName.class 
reference will create the shared lock for the super class and all sub classes.

More often than not, I've used this when I wanted the subclasses to stand alone.

Gregg Wonderly

On 2/7/2011 10:00 PM, Patricia Shanahan wrote:
> I found a bad synchronization idiom in a couple of the QA test programs for
> outrigger. I've done what I can to grep for it, but be alert in case it shows up
> in code you are reading.
>
> A non-final class needs to assign a unique number to each object of the class,
> or any of its direct or indirect subclasses:
>
> // Declared in the class
> private static int nextID=0;
>
> // Inside a constructor, or a method called from the constructor
> synchronized(getClass()){
> id = nextID++;
> }
>
> The synchronization is ineffective, because getClass() can return different
> Class objects in a non-final class' constructor.
>
> Patricia
>
>
>
>


Mime
View raw message