Search code examples
javamultithreadingsynchronizedsynchronized-block

Any chance of deadlock with only one sync point?


I have two running threads calling few methods (5 or 6) where I specified synchronized block inside and use only one object to lock it. Is there any chance of deadlock with having only one sync point? So far, I haven't seen such a situation, but still. Thanks for help.


Solution

  • If you are only using synchronized calls (i.e. no join, wait, notify, etc.) then the only way you can "deadlock" (using the term broadly here) is if one of the threads fails to exit the synchronised block (e.g. executes an infinite loop, doesn't return from a call to request some resource, etc.). So, yes, it's possible.