When do remote interface get invaliated? Can I cache them?

Discussions

EJB design: When do remote interface get invaliated? Can I cache them?

  1. Hello,

    I am designing an application, and considering using the "Service Locator" pattern, acting as a singleton that will cache jndi context, and bean home and remote interfaces. However I am unsure whether caching of remote interface is a problem or not:

    1) Under what circumstances will the cached remote interface for a stateless session bean be invalidated?

    2) Under what circumstances will the cached remote interface for an Entity Bean be invalidated?

    3) Assuming that I cache Stateful session bean remote interfaces in a Servlet HTTPSESSION, under what circumstances will the cached remote interface for Stateful session bean be invalidated?

    4) Finally, do I have to utilise home handles instead of remote interfaces for any of these situations? If so, why?

    Thanks
  2. Instead of caching remote interface its always better to cache Handles.
    Handles are serializable entities
    There are 2 types
    Home & Remote Handles
    Handle handle = myEJBObject.getHandle();//where myEJBObject is remote i/f
    HomeHandle = myHome.getHomeHandle();//myHome is home i/f

    Regarding yr question:
    Following are few scenarios where it gets invalidated

    1>connection timeouts

    2>Bean passivation

    3>Server/machine crash

    Cheers
    Amit