"Mr.Bad" <[EMAIL PROTECTED]> writes:

> Except doesn't the lock happen -after- the method has started with a
> synchronized block, and -before- the method starts with the
> synchronized method keyword? I'm not sure at all.

I'm pretty sure that, in the code generated by most compilers, a
synchronized method grabs the lock immediately after invocation and
releases it immediately before return, so that it will actually
compile into exactly the same bytecode as a synchronized(this){} block
around the entire body of the method.

For compilers in which this is not the case, synchronized methods will
probably result in slightly trimmer code than synchronized blocks for
methods with multiple return points (a single instruction to release
the lock rather than one instruction per return).

Of course, any compiler might chose to inline your method, especially
if it's static or final, so who knows.  There's no guaranteed benefit
to either of the "synchronized" constructs in terms of generated
bytecode.  Compiler-specific details should be ignored.

-S

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

Reply via email to