Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Lock()-clarification needed

 
Palraj Jayaraj
Ranch Hand
Posts: 36
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 9838
103
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have a look at the comments of the lock-method. Because it gives you all you need to know and understand the code.
 
Palraj Jayaraj
Ranch Hand
Posts: 36
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the fast reply.
I'll go through it and will let you know my feedback
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic