Thread safety mechanism

The following class is not thread safe (as proved in the Proof that the following code is not thread protected )

Is there any infrastructure that can help with compile time / runtime analysis and tell us that the following is not thread safe?

For compile time, ideally, wiggly appears in Eclipse and tells us that the class is not thread safe?

During runtime, will any static code analysis capture the class as thread safe?

public class LazyInitRace {
   private ExpensiveObject instance = null;

    public ExpensiveObject getInstance() {
    if (instance == null)
      instance = new ExpensiveObject();
    return instance;
   }
}
+4
source share
3 answers

FindBugs , , .. , . JCIP, , @Immutable.

, , , .

+4

, .

, race, : instance null . , Java, :

public class LazyInitRace {
  private static class Container {
    public final static ExpensiveObject INSTANCE = new ExpensiveObject();
  }

  public ExpensiveObject getInstance() {
    return Container.INSTANCE;
  }
}

, , , ( ), - .

.

0

, , , google.

- , /run time , ?

www.contemplateltd.com, . .

, , Eclipse , ?

http://www.checkthread.org/index.html , This is an open source project that you can see examples here

0
source

All Articles