aspose file tools*
The moose likes EJB and other Java EE Technologies and the fly likes why stateless bean is not singleton Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "why stateless bean is not singleton" Watch "why stateless bean is not singleton" New topic
Author

why stateless bean is not singleton

R Jelda
Greenhorn

Joined: May 13, 2002
Posts: 26
Hi,
It might be a dumb question.
I don't see any importance of pooling stateless beans.

Why not a stateless bean is singleton (one per server in cluster environment).

I have got this doubt till now somany times but no one can clear this.
I would be thankful,if any one of you can help me in explaining main differences.

Whenever I implement a stateless bean, the work is almost like a singleton. Actually I gain performance with singleton (ofcourse). Then why should I use stateless beans in my environment.

One scenario is, I have configurator-component which needs to read configuration from file. Ofcourse this is singleton. why this component needs to be a stateless?

Thanks in advance,
Jelda


"If you have an apple and I have an apple and we exchange apples then you and I will still each have one apple. But if you have an idea and I have an idea and we exchange these ideas, then each of us will have two ideas." -George Bernard Shaw
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30501
    
150

Jelda,
The stateless sesion bean can take care of transactions for the client. So while the SSB is executing, only one user can be in it at a time. For a singleton, this would mean you could have only one user in the system. That would bring concurrency to a grinding halt.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
R Jelda
Greenhorn

Joined: May 13, 2002
Posts: 26
Then you mean, if in my application there is no need to maintain Transactions on particular slsbs then I can use singleton instances or?

If so fine. But here I would like to know how others are also using slsb concept even if they don't require Transactions.

please clarify me with some more information.
Thanks in advance,
Jelda
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30501
    
150

Transactions are just an example. Another common example is security. If you are not using any of the services an EJB provides, than a singleton is fine.
Roger Chung-Wee
Ranch Hand

Joined: Sep 29, 2002
Posts: 1683
This is more a matter of threading, I think. Unlike a servlet, which is typically instantiated once and then accessed by multiple threads, a session bean instance is accessed by a single thread. The EJB container creates as many bean instances as needed for concurrent requests (each running in a thread), usually subject to a user-defined maximum number.

So, it usually makes no sense to limit the number of instances to one, as this would cause the container to serialize requests to that instance and cause poor performance.


SCJP 1.4, SCWCD 1.3, SCBCD 1.3
sachin pathak
Greenhorn

Joined: Jun 05, 2002
Posts: 27
Hi,
I am not sure whether this is right thread to ask for some help. Since this topic( threading and related issues for an EJB environment) is very important, can somebody point me to a resource which discusses this thouroughly?

thanks in advance

Sachin
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: why stateless bean is not singleton