[concurrency-interest] Making copy of a reference to ReentrantLock

Rémi Forax forax at univ-mlv.fr
Fri Jan 21 13:16:00 EST 2011


On 01/21/2011 06:29 PM, Navin Jha wrote:
>
> Thanks. What about using final keyword inside the method for the local 
> reference, what is the reason for that?
>

To get an error when you update the local reference instead of the 
corresponding field.
Or here because the field is also declared final (assignable once in the 
constructor).

Rémi

> *From:*Joe Bowbeer [mailto:joe.bowbeer at gmail.com]
> *Sent:* Friday, January 21, 2011 11:53 AM
> *To:* Navin Jha
> *Cc:* concurrency-interest at cs.oswego.edu
> *Subject:* Re: [concurrency-interest] Making copy of a reference to 
> ReentrantLock
>
> Note that this is a local reference not a local copy. Reusing a local 
> reference eliminates one (slower) instance variable lookup at runtime.
>
>     On Jan 21, 2011 8:39 AM, "Navin Jha" <navin.jha at fxall.com
>     <mailto:navin.jha at fxall.com>> wrote:
>
>     I was looking at the CopyOnWriteArrayList.java source code and I
>     see that in all the modification methods a copy of the lock is
>     made first, something like:
>
>     public E set(int index, E element) {
>
>                     final ReentrantLock lock = this.lock;
>
>                     lock.lock();
>
>     ................................... // rest of the method
>
>     I understand that making local copies of object variables would
>     reduce contention but is that the reason for doing this in this
>     case or something else?
>
>     Regards,
>
>     Navin
>
>
>     _______________________________________________
>     Concurrency-interest mailing list
>     Concurrency-interest at cs.oswego.edu
>     <mailto:Concurrency-interest at cs.oswego.edu>
>     http://cs.oswego.edu/mailman/listinfo/concurrency-interest
>
>
> _______________________________________________
> Concurrency-interest mailing list
> Concurrency-interest at cs.oswego.edu
> http://cs.oswego.edu/mailman/listinfo/concurrency-interest

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://cs.oswego.edu/pipermail/concurrency-interest/attachments/20110121/73cc56be/attachment.html>


More information about the Concurrency-interest mailing list