The second synchronizes the entire method.  The internal synchronized
block lets you lock a specific chunk of code.  Better, you get to lock on
a specific object, so you can control access to the object rather than the
method.

On 31 Dec 2000, Mr.Bad wrote:

> Hey, so, just wondering here, for my own edification: is there an
> advantage to doing this:
> 
>         public void gar(int foo) {
>             synchronized(this) {
>                 // stuff happens here;
>             }
>         }
> 
> ...rather than this:
> 
>         public synchronized void gar(int foo) {
>             // stuff happens here;
>         }
> 
> ? The first is an idiom I've run across a few times in Fred code, and
> I've never seen it used before.
> 
> ~Mr. Bad
> 
> -- 
>  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>  /\____/\   Mr. Bad <[EMAIL PROTECTED]>
>  \      /   Pigdog Journal | http://pigdog.org/ | *Stay*Real*Bad*
>  |  (X \x)   
>  (    ((**) "If it's not bad, don't do it.
>   \  <vvv>   If it's not crazy, don't say it." - Ben Franklin
>  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> 
> _______________________________________________
> Freenet-dev mailing list
> [EMAIL PROTECTED]
> http://lists.sourceforge.net/mailman/listinfo/freenet-dev
> 
> 


_______________________________________________
Freenet-dev mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/mailman/listinfo/freenet-dev

Reply via email to