All Downloads are FREE. Search and download functionalities are using the official Maven repository.

resources.report.rules.pmd.DoubleCheckedLocking.html Maven / Gradle / Ivy

Go to download

Sanity4J was created to simplify running multiple static code analysis tools on the Java projects. It provides a single entry point to run all the selected tools and produce a consolidated report, which presents all findings in an easily accessible manner.

The newest version!


DoubleCheckedLocking


DoubleCheckedLocking

Partially created objects can be returned by the Double Checked Locking pattern when used in Java. An optimizing JRE may assign a reference to the baz variable before it creates the object the reference is intended to point to. For more details see http://www.javaworld.com/javaworld/jw-02-2001/jw-0209-double.html.

This rule is defined by the following Java class: net.sourceforge.pmd.rules.DoubleCheckedLocking

Example:

                
  
public class Foo {
  Object baz;
  Object bar() {
    if(baz == null) { //baz may be non-null yet not fully created
      synchronized(this){
        if(baz == null){
          baz = new Object();
        }
      }
    }
    return baz;
  }
}
 
      
            




© 2015 - 2024 Weber Informatics LLC | Privacy Policy