J2EE applications usually invoke the same EJBs several times. EJB lookups are expensive, a possible way to reduce that overhead is to cache the bean home. There are many ways to do that, the following example is not the best but maybe the simplest: uses the singleton design pattern.
import javax.naming.NamingException;
import javax.naming.InitialContext;
import javax.rmi.PortableRemoteObject;
public class MyBeanHomeCache {
private static MyBeanHome home = null;
public static MyBeanHome getHome() throws NamingException {
try {
if (home == null) {
InitialContext context = new InitialContext();
home = (MyBeanHome) PortableRemoteObject.narrow(
context.lookup("test.myBean"),
MyBeanHome.class);
}
return home;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
Popularity: 1% [?]
Related posts:
- Developing Applications with JBoss and Hibernate: Part 2 Adding a web client to your project There are several...
- How to compress a file in GZIP format Gzip is a popular tool to compress a file in...
- How to convert List to Set (ArrayList to HastSet) In previous article, you learn about how to compress a...
- Modifying and Uncommitting Java Filter Response Aim The aim of this tutorial is to be able...
- Creating a game on Google Android game with Flixel – Getting Started The iPhone has taken the world by storm, but with...
Related posts brought to you by Yet Another Related Posts Plugin.
RSS Feed
Twitter

февруари 5th, 2010
admin
Posted in 
