in almost all the examples u saw to a ServiceLocator
- Posted by: Alon Agmon
- Posted on: November 01 2004 12:01 EST
it was implemented in a webApp as a singleton that caches the home's in a map while in serving EJB it wasnt a singleton and it didnt use the cach
is there a reason why ServiceLocators serving EJB's cant be singletons or to cach the resources ?
I believe its because of this:
Doing JNDI lookup cache in J2EE 1.3 and higher may cause application problems. And WAS already has build-in JNDI lookup cache, there is no need for JNDI look up cache. Please refer to http://www-106.ibm.com/developerworks/websphere/techjournal/0410_woolf/0410_woolf.html
for more information.
thanks for the reply...
well ok ,
why cant it be a singleton?
if the bean holds its resource after he used the serviceLocator like
BeansResource = ServiceLocator
so it has its resource for his entire lifecycle
why sould the ServiceLocator be created everyTime a bean is activated/created ?
In my opinion, it CAN be a singleton.
It need not be getInstance()/created everytime. (atleast in our current project, we getInstance() the singleton once, and store it as a member variable in the EJB.
What is bad, is having caching INSIDE the service locator. Sorry if my original answer was not to the point ;-)