Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Singleton Pattern and EJB  RSS feed

 
Desai Sandeep
Ranch Hand
Posts: 1157
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
As Singleton Pattern suggests having global access to an instance of the class -- And the class being allowed only one instance object, I was wondering if any of the EJB components, viz., HomeObject,RemoteObject or the Bean(Entity or Session) is based on this pattern.
Out of the above 3 essential components of EJB, HomeObject seems likely to based on Singleton Pattern.I would like to be corrected though!!
I believe, HomeObject as a candidate for Singleton pattern, if:

  • The EJB client, who may probably do a lookup on the HomeObject, any number of times returns the same instance of HomeObject

  • If that is correct, there would be only instance of HomeObject, and all the EJB clients will have global access to its instance - which means HomeObject is based on Singleton Pattern!!!
    Please let me know your views on this.
    Thanks in advance,
    Sandeep

    • Sun Certified Programmer for Java 2 PlatformScored 93 per cent
    • Oracle JDeveloper Rel. 3.0 - Develop Database Applications with JavaScored 56 out of 59
    • IBM Enterprise Connectivity with J2EEScored 72 per cent
    • Enterprise Development on the Oracle Internet PlatformScored 44 out of 56

    • [This message has been edited by Desai Sandeep (edited May 06, 2001).]
 
Peter den Haan
author
Ranch Hand
Posts: 3252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Beware of clustered environments - in a clustered EJB server, very few singletons are really singletons.
- Peter
 
Desai Sandeep
Ranch Hand
Posts: 1157
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Peter,
What does clustered EJB server mean?How does it hamper Singleton Pattern?What happens behind the scene?Please do let me know.
Do the vendors have the authority to break the patterns, which Sun (may or maynot in this case!!) has specified.
Also, I am curious to know, what happens, if the EJB Client writes this code:

If Singleton pattern is maintained, then I suppose home1 and home2 should hold the same HomeObjects.
How do I verify this?Like EJBObject, I donot have a method - isIdentical(EJBObject) in the EJBHome.Can I assume that the absence of such a method in the HomeObject as the basis for Singleton pattern design?
Please advise.
Regards,
Sandeep

  • Sun Certified Programmer for Java 2 Platform Scored 93 per cent
  • Oracle JDeveloper Rel. 3.0 - Develop Database Applications with Java Scored 56 out of 59
  • IBM Enterprise Connectivity with J2EE Scored 72 per cent
  • Enterprise Development on the Oracle Internet Platform Scored 44 out of 56

  • [This message has been edited by Desai Sandeep (edited May 07, 2001).]
 
Peter den Haan
author
Ranch Hand
Posts: 3252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What does clustered EJB server mean?
Multiple servers integrated to form one big "virtual" EJB server. There are two reasons for doing this. (1) Scalability: if you need to handle more load, just add more servers. (2) Failover: if one server fails, its workload can be picked up by the others, ideally without a user ever noticing this.
How does it hamper Singleton Pattern?What happens behind the scene?Please do let me know.
You have as many JVMs as you have servers in the cluster. Most of the things people do to realise the singleton pattern won't work in a clustered environment. Static variables? There may be as many copies as there are JVMs. Servlets? The same. EJBs of any kind? The same, even if load is close to zero. Home objects? Might be the same again, depending on how the server implements clustering.
By the way, I browsed through the EJB spec but could not find that it says in so many words that the home object needs to be a singleton. Of course, since it is bound in JNDI, you get (a stub for) the same object every time you resolve it... provided the JNDI tree is the same. Which, in a clustered environment, it need not be.
If Singleton pattern is maintained, then I suppose home1 and home2 should hold the same HomeObjects.
It surely will. You are resolving the same object from the same JNDI tree twice. I don't know if it would make any difference if this were not the case, though. The home object does not have any relevant state as far as the EJB developer is concerned.
- Peter

[This message has been edited by Peter den Haan (edited May 08, 2001).]
 
Desai Sandeep
Ranch Hand
Posts: 1157
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Peter,
I was hunting for information to confirm whether the HomeObject is based on Singleton Pattern.
I found an interesting link at theServerSide.com.Although it doesnot explicitly mention about this, but it certainly tries to explore the advantages of caching HomeObject references in the client.
It looks to be a good notion to consider doing a lookup once and and caching the HomeObject in the client for future reuse.
You opinion and references to literature on this are most welcome.
Regards,
Sandeep

  • Sun Certified Programmer for Java 2 Platform Scored 93 per cent
  • Oracle JDeveloper Rel. 3.0 - Develop Database Applications with Java Scored 56 out of 59
  • IBM Enterprise Connectivity with J2EE Scored 72 per cent
  • Enterprise Development on the Oracle Internet Platform Scored 44 out of 56

  • [This message has been edited by Desai Sandeep (edited May 09, 2001).]
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!