synchronized block

dannysh
dannysh used Ask the Experts™
on
Hi all

what will happen to a thread in the follwoing block:

synchronized (this) {
............
   synchronized(this) {
                ............
   }
}

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Commented:
Nothing. Since the thread already owns the monitor, the second synchronization will have no effect.

Or, to put it another way, the *first* synchronize statement will force the thread to wait for the monitor for this object. Once it has it, it will continue executing. The *second* synchronize statement will never cause a block, because it already has the monitor for this object.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial