Scott Gregory Miller <[EMAIL PROTECTED]> writes:

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

Java (stupidly) associates a (mutex) lock with every object, but
(arguably not quite as stupidly) doesn't represent methods as real
objects.  A synchronized method in Java is one that gets the lock
associated with its owner object before it runs, and releases it
before it returns.  So there's no difference between a synchronized
method and a method that synchronizes on "this" for the entirety of
its body.  The synchronized block is useful mainly in that it lets you
synchronize on *other* objects (but you're probably not designing
things well if you find yourself needing to do that very often).

-S

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

Reply via email to