why ServiceLocators serving EJB's cant be used as singletons

Discussions

EJB design: why ServiceLocators serving EJB's cant be used as singletons

  1. in almost all the examples u saw to a ServiceLocator
    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 ?

    Threaded Messages (3)

  2. 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.
  3. thanks[ Go to top ]

    thanks for the reply...

    well ok ,

    why cant it be a singleton?

    if the bean holds its resource after he used the serviceLocator like

    void activate(){
       BeansResource = ServiceLocator
                        .getInstanc()
                        .getResourceX()
    }

    so it has its resource for his entire lifecycle

    why sould the ServiceLocator be created everyTime a bean is activated/created ?
  4. It CAN be a singleton[ Go to top ]

    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 ;-)