The right way to write a singleton when developing for Android (or any multithreaded environment)
Oz Nusem
1005

As a new to learn java,could you tell me what is the different if the key word “synchronized” decorates a function like this :

public class LazySingleton {

private LazySingleton() {
}

private static volatile LazySingleton sInstance;

public static synchronized LazySingleton INSTANCE() {

if (sInstance == null) {
sInstance = new LazySingleton();
}
return sInstance;
}
}

thanks a lot!

Like what you read? Give null_number a round of applause.

From a quick cheer to a standing ovation, clap to show how much you enjoyed this story.