File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes Threads Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Threads" Watch "Threads" New topic


Willie Toma
Ranch Hand

Joined: May 11, 2001
Posts: 78
"A new lock is obtained for each entry into a synchronized code block."
Is each entry an object? What exactly is it...
Thanks in advance
John Dale
Ranch Hand

Joined: Feb 22, 2001
Posts: 399
By entry, they mean when the flow of execution of the program progresses from a statement outside the block to the inside of the block. (Method returns don't count.)
Does that answer address your question, or were you asking about the nature of the lock itself?
Willie Toma
Ranch Hand

Joined: May 11, 2001
Posts: 78
So for each block of code you can only have one entry?
Jim Yingst

Joined: Jan 30, 2000
Posts: 18671
No- if a method calls itself recursively, for example, a single block of code may be entered more than once, and each time a new lock is obtained on the same monitor. So a given monitor can have multiple locks held on it at the same time - the only catch is, they all have to be held by the same thread.

"I'm not back." - Bill Harding, Twister
I agree. Here's the link:
subject: Threads
It's not a secret anymore!