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;
}
}
source
share