Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

3
  • Ok. That raises another question in my mind. Since "Java allows only 1 of a set of synchronized methods to run at a time", and since the above code makes a call to another sync. method from inside a sync. method, will the thread holding a lock on this object will be allowed to run(get CPU share)? it seems to me it has created an infinite loop for itself. @ratchefreak Commented Jun 10, 2015 at 12:27
  • @Yeasir The thread will see that it already owns the lock on the object and just pass through the block after incrementing the owned counter. When leaving the method it will decrement the counter and release the lock if it hit 0. Commented Jun 10, 2015 at 12:30
  • Thanks a lot man. Got it. Not have enough reputation to vote you up guys. @ratchetfreak Commented Jun 10, 2015 at 12:39