[concurrency-interest] ThreadPoolExecutor implement question!

yangjs yangjs at alibaba-inc.com
Thu Sep 21 02:29:55 EDT 2006


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/699494ac/attachment.html 


More information about the Concurrency-interest mailing list