Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Lock()-clarification needed Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Lock()-clarification needed" Watch "Lock()-clarification needed" New topic
Author

Lock()-clarification needed

Palraj Jayaraj
Ranch Hand

Joined: Jun 06, 2012
Posts: 35

I'm currently preparing for OCJMD..
I've a doubt like



suppose, In the above code, I need to protect the variable 'a' from being accessed by other threads while execution.
I do not understand 'how invoking of lock() method on a 'ReentrantLock' object, will make the current thread to get a lock on the variable 'a'??

Thanks in advance.
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5450
    
  13

Have a look at the comments of the lock-method. Because it gives you all you need to know and understand the code.


SCJA, SCJP (1.4 | 5.0 | 6.0), SCJD
http://www.javaroe.be/
Palraj Jayaraj
Ranch Hand

Joined: Jun 06, 2012
Posts: 35

Thanks for the fast reply.
I'll go through it and will let you know my feedback
 
jQuery in Action, 2nd edition
 
subject: Lock()-clarification needed