---------- Forwarded message ----------
From: Manuranga Perera <[email protected]>
Date: Fri, Dec 19, 2014 at 3:15 PM
Subject: What is the recommended way to initialize singleton
To: dev <[email protected]>
Cc: Afkham Azeez <[email protected]>, Sameera Jayasoma <[email protected]>,
Sameera Perera <[email protected]>, Ruchira Wageesha <[email protected]>
Following kind of double locking code doesn't work [1] for singletons.
(please remove this if you see it in any place in the platform)
if(instance == null) {
synchronized(MyClass.class) {
if(instance == null) {
instance = new MyClass();
}
}
}
return instance;
There are multiple ways we can do this right. What is the best practice for
defining singletons in unavoidable situations?
[1] http://www.cs.umd.edu/~pugh/java/memoryModel/DoubleCheckedLocking.html
--
With regards,
*Manu*ranga Perera.
phone : 071 7 70 20 50
mail : [email protected]
--
With regards,
*Manu*ranga Perera.
phone : 071 7 70 20 50
mail : [email protected]
_______________________________________________
Dev mailing list
[email protected]
http://wso2.org/cgi-bin/mailman/listinfo/dev