У меня есть ServiceLocator, показанный ниже
public class ServiceLocator {
private static ServiceLocator serviceLocator = null;
InitialContext context = null;
HashMap serviceCache = null;
public ServiceLocator() throws NamingException {
context = new InitialContext();
serviceCache = new HashMap(5);
}
public synchronized static ServiceLocator getInstance()
throws NamingException {
if (serviceLocator == null) {
serviceLocator = new ServiceLocator();
}
return serviceLocator;
}
public Object getService(String jndiName) throws NamingException {
if (!serviceCache.containsKey(jndiName)) {
serviceCache.put(jndiName, context.lookup(jndiName));
}
return serviceCache.get(jndiName);
}
}
Может кто-нибудь сказать мне, почему мы должны хранить имя JNDI таким образом ??
serviceCache.put(jndiName, context.lookup(jndiName));