Browse Prior Art Database

Provision of a generic Enterprise JavaBean Home caching service Disclosure Number: IPCOM000014821D
Original Publication Date: 2001-Apr-16
Included in the Prior Art Database: 2003-Jun-20

Publishing Venue



The Enterprise JavaBeans* (EJB) architecture prescribes the use of EJB Homes as a factory for the creation and location of EJB instances. An application program must lookup a naming service using Java Naming and Directory Interface (JNDI), to obtain a reference to a specific EJB Home. Once the EJB Home is obtained, the application can then invoke the lifecycle management services provided by the EJB Home to create retrieve delete an EJB. The lookup of the EJB Home is a significant overhead, therefore the need to maintain a reference to the EJB Home, and reuse it as necessary, is crucial to the design of high-performance EJB-based systems. Web Application Servers do not provide such a service, leaving it to the application programmer to do this themselves. The application programmer will typically store a reference to the specific EJB Home, and retrieve it as required. The cached EJB Home reference, however, can become 'stale' this occurs when the EJB Container has suffered a crash, causing an error to be thrown when an application program tries to use the now stale EJB Home reference. An application programmer needs to code appropriate error-handling logic to handle such a situation arising. The invention provides a generic EJB Home caching service, which has a cache refresh mechanism in the event of an EJB Home becoming stale. The application programmer is provided with a simple interface to the caching service; a method returns an EJBHome reference giving the JNDI name of the EJB required. The application programmer codes a catch block for the exception 'javax.rmi.MarshalException', and in that block calls another method which signals to the caching service that a refresh of the cache is necessary. The invention consists of a Java class that implements the Singleton pattern, 'EjbHomeCacheHelper'. This class mediates client requests to the EJB server to retrieve the requested EJBHome. The interface to the EjbHomeCacheHelper consists of two static methods; EJBHome getHome(String jndiName) and EJBHome retryHome(String jndiName). A client application will first call the getHome() method to get the EJB Home reference from the cache. It will then call one of the available lifecycle methods (create(), findByPrimaryKey() ..) inside a try catch block which catches javax.rmi.MarshalException (this is the exception which will be thrown by the EJB container if the cached EJB Home reference is no longer valid). When this exception is caught, the client application can then call the retryHome() method, this method refreshes the cache before returning a new valid EJB Home reference.