EJB design: About Locator design pattern
From book 'J2ee Design Pattern' published by Sun, there is a Locator pattern. This mechanism can be implemented by a Ejb, it cache EJBHome objects in their pool. The first time client locate a home, it lookup this home, before return it add it to its pool for later using. But, I suspect that can this improve the performance? If I don't use it, the most I using JNDI to locate EJBHome is only once, oppositely; If I use it, first I have to lookup this locator by JNDI one time, if it is exist, that's fine I return. If not, Locator have to second lookup for the one I need, there are two 'lookup'. So by this way, the system maybe perform 2 'lookup'. Anyone has same feeling?
- Posted by: Wallace Zou
- Posted on: August 03 2002 10:21 EDT
From Sun Java Center J2EE Patterns (link):
<i>"The Service Locator abstracts the API lookup (naming) services, vendor dependencies, lookup complexities, and business object creation and provides a simple interface to clients. This reduces the client’s complexity. In addition, the same client or other clients can reuse the Service Locator."</i>
So, the amount of lookups is not the only dimension here. Using the Locator pattern, your client code is more independent of the location of the wanted resource/service/whatever.
We can implement Locator as a Singleton, not EJB. So we needn't at least one lookup for locating Locator. It's great.