如何自动清除instanceMap的key和value;当 getInstance() API 返回的 Conf 对象是 Garbage Collected using WeakHashMap 和 WeakReference ...?
//single conference instance per ConferenceID
class Conf {
private static HashMap<String, Conf> instanceMap = new HashMap<String, Conf>;
/*
* Below code will avoid two threads are requesting
* to create conference with same confID.
*/
public static Conf getInstance(String confID){
//This below synch will ensure singleTon created per confID
synchronized(Conf.Class) {
Conf conf = instanceMap.get(confID);
if(conf == null) {
conf = new Conf();
instanceMap.put(confID, conf);
}
return conf;
}
}
}