must the service locator a singleton?
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   zhebin_cong
Posted On:   Sunday, February 23, 2003 06:12 AM

from the "java core pattern" book,i have learned that the service locator is a singleton,but when i downloaded the petstore1.3.1_01 and opened the source code,i find the web tier locator is a singleton,but the ejb tier locator is not a singleton,why? the ejb tier locator as: public class ServiceLocator { private InitialContext ic; private static ServiceLocator me; public ServiceLocator() throws ServiceLocatorException { try { ic = new InitialContext(); } catch (NamingException ne) { throw new ServiceLocatorException(ne); } catch (Exception e) { throw new ServiceLocatorException(e); }    More>>

from the "java core pattern" book,i have learned that the service locator is a singleton,but when i downloaded the petstore1.3.1_01 and opened the source code,i find the web tier locator is a singleton,but the ejb tier locator is not a singleton,why?

the ejb tier locator as:




public class ServiceLocator {

private InitialContext ic;

private static ServiceLocator me;

public ServiceLocator() throws ServiceLocatorException {
try {
ic = new InitialContext();
} catch (NamingException ne) {
throw new ServiceLocatorException(ne);
} catch (Exception e) {
throw new ServiceLocatorException(e);
}
}

................
................
................
................


the web tier locator as:


public class ServiceLocator {

private InitialContext ic;
private Map cache; //used to hold references to EJBHomes/JMS Resources for re-use

private static ServiceLocator me;

static {
try {
me = new ServiceLocator();
} catch(ServiceLocatorException se) {
System.err.println(se);
se.printStackTrace(System.err);
}
}

private ServiceLocator() throws ServiceLocatorException {
try {
ic = new InitialContext();
cache = Collections.synchronizedMap(new HashMap());
} catch (NamingException ne) {
throw new ServiceLocatorException(ne);
} catch (Exception e) {
throw new ServiceLocatorException(e);
}
}

static public ServiceLocator getInstance() {
return me;
}

...............
...............
...............

   <<Less
About | Sitemap | Contact