[concurrency-interest] ThreadPoolExecutor implement question!
yangjs
yangjs at alibaba-inc.com
Thu Sep 21 04:48:21 EDT 2006
thx,
I think if it does as David said, the optimization should happend at compile time or VM runtime.
it is a lower level skill for application developer. is right?
----- Original Message -----
From: Hanson Char
To: dholmes at ieee.org
Cc: yangjs ; concurrency-interest at cs.oswego.edu
Sent: Thursday, September 21, 2006 4:03 PM
Subject: Re: [concurrency-interest] ThreadPoolExecutor implement question!
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/10537bf7/attachment-0001.html
More information about the Concurrency-interest
mailing list