[concurrency-interest] ThreadPoolExecutor implement question!

David Holmes dcholmes at optusnet.com.au
Thu Sep 21 03:33:32 EDT 2006


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,
-------------- next part --------------
An HTML attachment was scrubbed...
URL: /pipermail/attachments/20060921/52797253/attachment.html 


More information about the Concurrency-interest mailing list