commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From WHIRLYCOTT <p...@whirlycott.com>
Subject Re: concurrency and starting a synchronized block
Date Thu, 10 Feb 2005 18:24:57 GMT
Exactly - most books and documentation about resource exclusion about 
this make it abundantly clear that synchronized methods shouldn't call 
each other for this very reason.

Thanks for adding that point.

phil.

Oliver Zeigermann wrote:
> 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
> 

-- 
                                   Whirlycott
                                   Philip Jacob
                                   phil@whirlycott.com
                                   http://www.whirlycott.com/phil/

---------------------------------------------------------------------
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