File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes EJB and other Java EE Technologies and the fly likes ServiceLocator on the web tier and the EJB tier Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "ServiceLocator on the web tier and the EJB tier" Watch "ServiceLocator on the web tier and the EJB tier" New topic

ServiceLocator on the web tier and the EJB tier

Stephen Suen
Ranch Hand

Joined: Oct 30, 2003
Posts: 34
Sun PetStore 1.4 demonstrates two difference ServiceLocator implementations for the web tier and the EJB tier:


The one for the web tier uses the "singleton" strategy and also the "caching" strategy.

I wonder that why we need two different implementations. Is there any problem if we use a single one implementation that uses a cache for both web tier and EJB tier?

Any help will be appreciated.

Valentin Tanase
Ranch Hand

Joined: Feb 17, 2005
Posts: 704
Hi Stephen,

Not sure if I can help you much since I don�t remember much about PetStore application and the only thing I remember is that PetStore is probably one of the best examples proving that J2EE in general and Sun design patterns in particular are such low quality software solutions. This gave Microsoft the possibility to develop their .NET PetShop counterpart that uses 10 times less amount of code and performs several times better, while it provides the same functionality. It�s also funny when you think that were people trying to improve the PetStore app, but they used different patterns and practice that were forbidden by Sun. What a mess�
Hence my first advice to you would be to look somewhere else for design patterns and don�t take it very hard to understanding PetStore.
On the other hand, without pretending I�ll give you the right answer, one good reason to have two different service locators, is because the web tier has two possibilities: to access the ejbs through remote or local interfaces, depending upon the clustering architecture, or simply if the web server and ejb container runs in different jvms. As for the ejb service locator, it supposes to use always the local interfaces, since the application uses a session fa�ade.

I think, therefore I exist -- Rene Descartes
I agree. Here's the link:
subject: ServiceLocator on the web tier and the EJB tier
It's not a secret anymore!