While looking at some Singleton-classes used in Turbine (as ActionLoader,
PageLoader...) I realized, that the so-called Double-Checked Locking scheme
is used there:
class MySingleton {
private static MySingleton instance = null;
public static MySingleton getInstance() {
if (instance == null) {
synchronized (MySingleton.class) {
if (instance == null) {
instance = new MySingleton();
}
}
}
return instance;
}
}
JavaWorld published an article about DCL and potential risks some time ago
(http://www.javaworld.com/javaworld/jw-02-2001/jw-0209-double.html).
The most important issue is, that there is no guarantee the singletons are
actually initalized only once, if the server is hit by many concurrent
requests while initializing singletons.
A solution proposed by the auther of the article is to use eager
initialization:
class MySingleton {
private static MySingleton instance = new MySingleton();
public static MySingleton getInstance() {
return instance;
}
}
What do you think about using this in Turbine?
cya,
David
------------------------------------------------------------
To subscribe: [EMAIL PROTECTED]
To unsubscribe: [EMAIL PROTECTED]
Search: <http://www.mail-archive.com/turbine%40list.working-dogs.com/>
Problems?: [EMAIL PROTECTED]