TRS.NSPM
Declare all "public" methods as "synchronized"
Description
This rule flags any "public" method that is not declared as "synchronized"
A "public" method should be synchronized unless it has a Javadoc that describes the assumed invocation context and/or rationale for the lack of synchronization.
In the absence of planning out a set of concurrency control policies, declaring methods as synchronized at least guarantees safety (though not necessarily livens) in concurrent contexts (every Java program is concurrent to at least some minimal extent). With full synchronization of all methods, the methods may lock up, but the object can never enter into randomly inconsistent states (and thus engage incorrect behavior) due to concurrency conflicts. If you are worried about efficiency problems due to synchronization, learn enough about concurrent OO programming to plan out more efficient and/or less deadlock-prone policies (for example, read "Concurrent Programming in Java" by Doug Lea).
Example
package TRS;
public class NSPM {
public void method () { // violation
System.out.println("non synchronized public method");
}
}
Reference
http://www.infospheres.caltech.edu/resources/code_standards/recommendations.html
|