harmony-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Geir Magnusson Jr." <g...@pobox.com>
Subject Re: [classlib] Recognizing lock objects
Date Tue, 03 Oct 2006 16:56:20 GMT

Tim Ellison wrote:
> There are a number of places in the class library code where we create
> an object solely to use as a synchronized block 'lock'.
> For example, in RandomAccessFile we define a
>   private Object repositionLock = new Object();
> then in a number of methods
>   public int read()..
>    ..
>    synchronized(repositionLock) {
>      ...
>    }
> you get the idea.
> Using an instance of Object makes it hard to see (in profiling tools)
> which lock objects are 'hot', or how often a particular lock object is used.
> I'd like to replace the generic Object instance with a private type just
> for the purpose, like this:
>     private class RepositionLock {}
>     private Object repositionLock = new RepositionLock();

Why "RepositionLock"?  (curious about origin of the name)

> The usage would be the same, but it will then be easier to see if
> RandomAccessFile$RepositionLock becomes a choke point.
> Any objections or improvements to this proposed 'pattern' and putting it
> into various places throughout the class library?

I like it.  But, any benefit to having a general class 
o.a.h.whatever.LockObject rather than class private?


Terms of use : http://incubator.apache.org/harmony/mailing.html
To unsubscribe, e-mail: harmony-dev-unsubscribe@incubator.apache.org
For additional commands, e-mail: harmony-dev-help@incubator.apache.org

View raw message