Discussions

EJB programming & troubleshooting: ejbhome and initialcontext caching

  1. ejbhome and initialcontext caching (4 messages)

    Hi,

    If I am caching the EJBHome and InitialContext in implementing the servicelocator pattern, do I need to close the context after every EJB transaction using Context.close() method in the finally block?

    Any suggestion in this is highly appreciated.

    Thanks
    Suneer

    Threaded Messages (4)

  2. ejbhome and initialcontext caching[ Go to top ]

    Hi,

    usually you should not need to close the InitialContext. I suppose the EJB container should do this for you. Anyway - I know of at least one EJB container (BEA Weblogic) which does not close the context after lookup. That causes problems with security (Principals switch depending on the Identity used for the lookup!).

    So - close the InitialContext after the lookup. It seems good style to me.

    Cheers,

    René Zanner
  3. ejbhome and initialcontext caching[ Go to top ]

    Thanks very much for your suggestion.
    I use BEA Weblogic 6.1. I want to cache the initial context and EJBHome.
    Now, if I close the context every time in the finally block, will I still be able to use the cached context/ Home interface?

    Thanks,
    Suneer
  4. ejbhome and initialcontext caching[ Go to top ]

    Hi,

    it should be enough to cache the Home interfaces. We do that in our ServiceLocator pattern: we have a EjbHomeFactory which caches the Home interfaces in a Map.

    Why do you want to cache the InitialContext? I'm afraid that when you close it, you can't use it any longer for lookups.

    Cheers,

    René
  5. ejbhome and initialcontext caching[ Go to top ]

    Hi René,

    Thanks very much for your suggestion.
    I will implement your suggestions.

    Thanks again...

    Suneer