17 lines
476 B
Java
17 lines
476 B
Java
package singleton;
|
|
|
|
public class AppConfigSynchronized {
|
|
|
|
private static AppConfigSynchronized instance;
|
|
|
|
private AppConfigSynchronized() { /* load config */ }
|
|
|
|
// synchronized: only one thread can execute this method at a time
|
|
public static synchronized AppConfigSynchronized getInstance() {
|
|
if (instance == null) {
|
|
instance = new AppConfigSynchronized(); // safe — no other thread can be here
|
|
}
|
|
return instance;
|
|
}
|
|
}
|