• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Can I use Service Locator pattern from Session Facade

 
Jagmohan Negi
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 704
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Jagmohan Negi
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
plz let me know the code you are talking about
 
Valentin Tanase
Ranch Hand
Posts: 704
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The code is similar to the one posted on sun's site:

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

Regards.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic