The Artima Developer Community
Sponsored Link

Design Forum
Singleton Pattern in EJB

1 reply on 1 page. Most recent reply: Mar 27, 2007 11:56 PM by kinder98h kinder98h

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
Rajagopal

Posts: 3
Nickname: rajagopaly
Registered: Mar, 2005

Singleton Pattern in EJB Posted: Mar 15, 2005 9:36 PM
Reply to this message Reply
Advertisement
Hi..

I am glad to know about how the Singleton Pattern works in EJB?
I know that the Singleton class guarantees per JVM, But any AppServer uses multiple JVM's for Performance Reasons.

Can you pls Let me know how to implement Singleton Pattern. and any links for good articles.

Regds
Rajagopal Y


kinder98h kinder98h

Posts: 1
Nickname: kinder98h
Registered: Mar, 2007

Re: Singleton Pattern in EJB Posted: Mar 27, 2007 11:56 PM
Reply to this message Reply
Hi, there is a answer, find in other forum.


---------------------------------------------------

Answer
No, You cannot implement a Singleton in EJB. A way to do this could be to implement an RMI or CORBA object.



Comments and alternative answers

Comment on this FAQ entry

EntityBean as Singleton?
Ravi Shankar, Nov 26, 2001 [replies:1]
Wouldn't the following scheme work like a singleton? Define a read-only BMP EntityBean with <prim-key-class> as String. In the ejbFindByPrimaryKey() method, always return a hard-coded string (irrespective of the primary key value passed in). Wouldn't all clients then get a reference to the same EJB instance? Regards Ravi




Does it work? Did you try?
Chris Duerr, Mar 22, 2005
The ejb specification states: at any time, there is only one client thread per bean instance active. Therefore I expect that there might more than one instance of an entity bean, even if there is only one data set to represent.

Setting the entitiy bean read-only means that there is no call to the (unneseccary) ejbStore(). A read-only bean still may be represented by more than one instance.

But this is blank theory, so does it in practice work? Did you try?



Use a stateless session bean with an instance pool size of 1.
Dominic Cioccarelli, Feb 14, 2002 [replies:2]
You can (in many application servers) determine the instance pool size for each bean. By implementing a stateless session bean with an instance size of 1, you effectively have a singleton. The downside is that setting the pool size is vendor specific.


Re: Use a stateless session bean with an instance pool size of 1.
David Li, Feb 21, 2002 [replies:1]
My impression is that a stateless session bean instance is not free threaded and does not allow a re-entry while another client is using it. The other way to view it is that if a single instance of a stateless session bean were a singleton and were able to serve multiple client simultanouly, why would you ever need to put more than one bean instances in a pool? Hope somebody can confirm my impression or tell me why I am wrong. Thanks David


Re[2]: Use a stateless session bean with an instance pool size of 1.
Kirill Fakhroutdinov PREMIUM, May 7, 2002
You are right that this singleton EJB can not be multithreaded - as any other EJB. Only one client at a time would be able to access it. And because other EJBs can not wait because of the absence of synchronization mechanisms - they probably will be just failing (unless application server/container will be able to put them "on hold" - that I doubt).

P.S. Read-only singleton could be free-threaded, but read-write singleton usually has to be synchronized.



Use Of Singleton Pattern in EJB.
santosh Terkhedkar, Sep 9, 2002 [replies:1]
I think use of singleton pattern is possible in EJb, we can use JNDI to store arbitrary objects and lookup these objects through jndi,but use of singleton pattern in ejb is not useful. other way to achive this could be to write a java class and call this bean from within java class and make only one instance of this class.



Re: Use Of Singleton Pattern in EJB.
Ankush Purwar, Jun 20, 2005
Using your approach write a java class and call this bean from within java class and make only one instance of this class doesn't work in clustering.

Flat View: This topic has 1 reply on 1 page
Topic: Design, Methodology, and The Psychology of Human Denial Previous Topic   Next Topic Topic: entity attribute diagram

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use