[concurrency-interest] general performance question

Nathan Reynolds nathan.reynolds at oracle.com
Wed Dec 21 11:45:35 EST 2011


Use javap to check the bytecode output from both.  From a performance 
perspective, I don't think it shouldn't matter.  However, from an API 
perspective it matters.  Let's say you derive the class and implement 
someMethod.  If the synchronized keyword is on the method, then Eclipse 
or FindBugs could be configured to warn you that the overridden method 
doesn't declare synchronized.  The tool suggests that this means the 
overridden method is not correctly synchronized.  On the other hand, 
"synchronized(this)" will trigger Eclipse or FindBugs to warn you that 
the code is synchronizing on a publicly accessible object.  This means 
that if another piece of code synchronizes on the object then there 
might be an unintended scalability problem.

Nathan Reynolds 
<http://psr.us.oracle.com/wiki/index.php/User:Nathan_Reynolds> | 
Consulting Member of Technical Staff | 602.333.9091
Oracle PSR Engineering <http://psr.us.oracle.com/> | Server Technology

On 12/21/2011 8:45 AM, Jha, Navin wrote:
> Is there an advantage to do:
>
> someMethod(...) {
>          synchronized(this) {
>                  ................
>                  ................
>                  ................
>          }
> }
>
> instead of:
> synchronized someMethod(...) {
> ................
> ................
> ................
> }
>
> Even when the entire method needs to be synchronized? I understand in general it is a good practice to use synchronized blocks since more often than not only certain lines need to be synchronized.
>
> -Navin
>
> _______________________________________________
> Concurrency-interest mailing list
> Concurrency-interest at cs.oswego.edu
> http://cs.oswego.edu/mailman/listinfo/concurrency-interest
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://cs.oswego.edu/pipermail/concurrency-interest/attachments/20111221/3ca7d25a/attachment.html>


More information about the Concurrency-interest mailing list