Can I let a static field of a class keep a reference to an instance of itself? If so, will it keep alive in the jvm without anyone else keeping a reference?
public class StatTest {
private static StatTest statTest;
public static StatTest getStatTest () {
if (statTest== null) {
statTest= new StatTest ();
statTest.init();
}
return statTest;
}
private StatTest() { }
}
StatTest.getStatTest()from more than one thread). To compare different singleton implementations (including some thread-safe ones), check stackoverflow.com/questions/7121213/singleton-instantiation/…, an answer I wrote some time ago.