This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes EJB and other Java EE Technologies and the fly likes Can I use Service Locator pattern from Session Facade Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Can I use Service Locator pattern from Session Facade" Watch "Can I use Service Locator pattern from Session Facade" New topic
Author

Can I use Service Locator pattern from Session Facade

Jagmohan Negi
Greenhorn

Joined: Aug 24, 2005
Posts: 27
Can I use a Service locator from a session facade as given below:

*************************************************
public class ACSSessionServiceLocator {

private InitialContext ic;
private Map cache;

private static ACSSessionServiceLocator me;

static {
try {
me = new ACSSessionServiceLocator();
} catch(NamingException se) {
throw new RuntimeException(se);
}
}
.
.
.
.
.
******************

plz let me know the is there any disadvantage of using static in it. or it is beneficial to use it like as i have coded.
Valentin Tanase
Ranch Hand

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

There are several reasons for avoiding using singletons with j2ee applications. One reason is that at least in theory there could be situations when two or more such singletons could be created in the same JVM if the getInstance method is not properly synchronized (and synchronization is another forbidden word in the j2ee world :-)). Another reason might be that in a clustered environment you�ll have as many singletons as server instances and your application should be designed accordingly.
However none of these pitfalls could be a problem for your code. As a matter of fact, I�ve seen a legacy application that uses home factory pattern within Struts action classes and it runs pretty well. It supports more than 3000 concurrent users and was deployed in production more than 3 years ago. If this makes you feel better I�ll tell you that the code they�re using looks pretty similar to the one you�ve posting :-)
Regards.


I think, therefore I exist -- Rene Descartes
Jagmohan Negi
Greenhorn

Joined: Aug 24, 2005
Posts: 27
plz let me know the code you are talking about
Valentin Tanase
Ranch Hand

Joined: Feb 17, 2005
Posts: 704
The code is similar to the one posted on sun's site:

http://java.sun.com/blueprints/corej2eepatterns/Patterns/ServiceLocator.html

Regards.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Can I use Service Locator pattern from Session Facade
 
Similar Threads
Business Delegate in JEE5
must the service locator be a singleton
mock question: design pattern
DTO/TO - Which Tier??
service locator used before or after session facade