[concurrency-interest] ThreadPoolExecutor implement question!
Hanson Char
hanson.char at gmail.com
Thu Sep 21 04:03:28 EDT 2006
Is such optimization only applicable to final fields, but not instance
member fields in general ? Does this mean if a final field is accessed more
than once in a method, it's always faster to assign it first to a local
variable ?
Hanson
On 9/21/06, David Holmes <dcholmes at optusnet.com.au> wrote:
>
> This was an optimization to work around a VM "glitch" which where the
> final field is loaded on each access (as a normal field would be) rather
> than loading it once. To avoid this it is copied to a local variable.
>
> Cheers,
> David Holmes
>
> -----Original Message-----
> *From:* concurrency-interest-bounces at cs.oswego.edu [mailto:
> concurrency-interest-bounces at cs.oswego.edu]*On Behalf Of *yangjs
> *Sent:* Thursday, 21 September 2006 4:30 PM
> *To:* concurrency-interest at cs.oswego.edu
> *Subject:* [concurrency-interest] ThreadPoolExecutor implement question!
>
> hi,all
>
> when I read ThreadPoolExecutor code ,I found it's declare the mainLock use
> "final" ,
>
> private final ReentrantLock mainLock = new ReentrantLock();
>
> many method use the lock guarding state, use case as follow:
>
> final ReentrantLock mainLock = this.mainLock;
> mainLock.lock();
> try {
> // some code
> } finally {
> mainLock.unlock();
> }
>
> My question is the instance field already use "final" to mainLock,
> why every method need copy mainLock reference to final local var.
>
> this puzzle me,who can tell me why ? thanks.
>
> Best regards,
>
>
> _______________________________________________
> Concurrency-interest mailing list
> Concurrency-interest at altair.cs.oswego.edu
> http://altair.cs.oswego.edu/mailman/listinfo/concurrency-interest
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: /pipermail/attachments/20060921/8f96af20/attachment.html
More information about the Concurrency-interest
mailing list