Originally posted by manish ahuja:
Hi All
I was going through Sun BluePrints where they show 2 types of service locators
quoting from the blue prints
***************************************
The Java Pet Store sample application, v1.3.1 has two service locators: a Web-tier class ServiceLocator , and an Enterprise JavaBeansTM (EJB) tier class, also called ServiceLocator . Both classes manage lookup and caching of enterprise bean home interfaces, JMS and database connection factories, and environment entries within their respective tiers. The only difference between them is that the Web-tier class is a singleton, and it caches the objects it looks up. The EJB-tier class is not a singleton, and does not cache.
****************************************
Here are the links to the code piece
1) the 1 that looks up as well as caches
http://java.sun.com/blueprints/code/jps131/src/com/sun/j2ee/blueprints/servicelocator/web/ServiceLocator.java.html
This is synchronized. My question is does it have to be that way. In the above code for caching was Singleton necessary
2) the 2nd one looks up but does not cache and is neither a Singleton
http://java.sun.com/blueprints/code/jps131/src/com/sun/j2ee/blueprints/servicelocator/ejb/ServiceLocator.java.html
Do post your viewpoints on the same
Rgrds
Manish
Originally posted by manish ahuja:
What I intended to ask from my post was Cant we have caching without resorting to Singleton
Say I use the caching part of the code mentioned in the original post in Scenario1 & force it on scenario2.
Wont I be able to still use caching
In short do we have to have singleton to enable caching or I can have caching even without being a Singleton class
Originally posted by manish ahuja:
Talking about DI/IOC & the new EJB3.0 can we say we can do away with the Service locator & Singleton pattern approach totally as we no longer would be needing these lookups[/QB]
Originally posted by Aneesha Singh:
The thing is that the reason for using a singleton is to provide a single cache. Otherwise you could have multiple instances of the caching class and that would kind of defeat the purpose.
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
WHAT is your favorite color? Blue, no yellow, ahhhhhhh! Tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
|