Double Check Locking and Singleton
Although you can use volatile to fix Double Check Locking problem in jdk1.5, but the recommended way is still not to use DCL since the volatile is too expensive. The recommended way is still:
private static class LazySomethingHolder {
public static Something something = new Something();
}
public static Something getInstance() {
return LazySomethingHolder.something;
}
http://www-128.ibm.com/developerworks/java/library/j-jtp03304
No comments:
Post a Comment