com.github.xphsc.lang.Singleton Maven / Gradle / Ivy
package com.github.xphsc.lang;
import com.github.xphsc.util.ClassUtil;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
/**
* Created by ${huipei.x} on 2017-5-25.
*/
public final class Singleton {
private static Map, Object> pool = new ConcurrentHashMap();
private Singleton() {
}
public static T get(Class clazz, Object... params) {
Object obj = pool.get(clazz);
if(null == obj) {
Class var3 = Singleton.class;
synchronized(Singleton.class) {
obj = pool.get(clazz);
if(null == obj) {
obj = ClassUtil.newInstance(clazz, params);
pool.put(clazz, obj);
}
}
}
return (T) obj;
}
public static T get(String className, Object... params) {
Class clazz = ClassUtil.loadClass(className);
return (T) get(clazz, params);
}
public static void remove(Class> clazz) {
pool.remove(clazz);
}
public static void destroy() {
pool.clear();
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy