commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Oliver Zeigermann <oliver.zeigerm...@gmail.com>
Subject Re: concurrency and starting a synchronized block
Date Thu, 10 Feb 2005 18:20:16 GMT
On Thu, 10 Feb 2005 13:09:14 -0500, WHIRLYCOTT <phil@whirlycott.com> wrote:
> 2) synchronize on the containing object's monitor:
> 
>         ...
>         public synchronized whatever(Object arg1) {...}
>         public synchronized something() {...}
>         ...
> 

Blindly doing this can easily lead to deadlocks. Consider thread #1 in
method whatever accesses another synchronized object and needs to wait
for thread #2 to release the lock on it. Now thread #2 tries to access
method something and - of course - needs to wait for thread #1 to
release the lock on that first objec. Now both threads mutually wait
for each other and you have a deadlock.

Oliver

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message