Jtest logo




Contents  Previous  Next  Index

TRS.NSM


Do not use the synchronized modifier

Description

This rule flags any occurrence of the synchronized modifier.

The "synchronized" modifier is equivalent to the "synchronized" statement, but use of only the statement form makes the code easier to understand and debug. However, the "synchronized" modifier may make the code slightly more efficient than the "synchronized" statement.

Example

 package TRS;
 
 class NSM {
     synchronized void method () {
         // ...
     }
 }

Repair

Use the "synchronized" statement instead of the "synchronized" modifier, i.e.

 class NSM_fixed {
     void method () {
         synchronized (this) {
             // ...
         }
     }
 }

Reference

Haggar, Peter. Practical Java - Programming Language Guide. Addison Wesley, 2000, pp.122 - 134.


Contents  Previous  Next  Index

ParaSoft logo
(888) 305-0041 info@parasoft.com Copyright © 1996-2001 ParaSoft