Re: Bad idiom

2011-02-08 Thread Gregg Wonderly
On 2/8/2011 9:22 AM, Patricia Shanahan wrote: For shared counters, there is no need for an explicit MyClassName.class reference. All I did was make the get-and-increment a static synchronized method in the same class in which the counter itself is a static field. A static synchronized method is

Re: Bad idiom

2011-02-08 Thread Patricia Shanahan
For shared counters, there is no need for an explicit MyClassName.class reference. All I did was make the get-and-increment a static synchronized method in the same class in which the counter itself is a static field. Doing local counters per class is fine, as long as every use of a single co

Re: Bad idiom

2011-02-08 Thread Gregg Wonderly
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 t

Re: Bad idiom

2011-02-08 Thread Patricia Shanahan
I didn't think you would need JLS references for what I was actually saying. I fixed it in outrigger by extracting a static synchronized method containing the critical region code. That naturally synchronizes on the Class object for the class containing the call, not the class object for the o

Re: Bad idiom

2011-02-08 Thread Niclas Hedhman
U... After reading your complaint, I think I just misunderstood your objection in the getClass() is incorrect synchronization object which I agree with. The direct reference to the superclass object instance is what should be done. I just got 'jumpy' when I read that "getClass() in a constructo

Re: Bad idiom

2011-02-08 Thread Patricia Shanahan
On 2/7/2011 11:59 PM, Niclas Hedhman wrote: On Tue, Feb 8, 2011 at 12:00 PM, Patricia Shanahan wrote: The synchronization is ineffective, because getClass() can return different Class objects in a non-final class' constructor. This is important news to me... Are you sure about that? Got any

Re: Bad idiom

2011-02-08 Thread Niclas Hedhman
On Tue, Feb 8, 2011 at 12:00 PM, Patricia Shanahan wrote: > The synchronization is ineffective, because getClass() can return different > Class objects in a non-final class' constructor. This is important news to me... Are you sure about that? Got any JLS reference/pointer? Cheers -- Niclas He