public class UserKatalog {
private static UserKatalog instance;
private static Object lock=new Object();
private UserKatalog()
{
System.out.println("UserKatalog singleton nesnesi olusturuldu");
}
public static UserKatalog getInstance()
{
if(instance==null)
{
synchronized (lock) {
if(instance==null)
{
return new UserKatalog();
}
}
}
return instance;
}
}
public class Test {
public static void main(String[] args) {
UserKatalog.getInstance();
}
}
Ekran çıktısı
UserKatalog singleton nesnesi olusturuldu