Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Stateless session beans are pooled.  RSS feed

 
Rahul Bhattacharjee
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I know that stateless session beans are pooled , and they say its because of scalability.
I have the following doubt:

After each method call the EJBObject (I mean the implementation of the remote component interface) sends the bean back to the pool and for invocation of another method it again takes up a bean from the pool.But if its stateless then when a business method is called then the method is copied in the caller thread's stack.And multiple clients can be served by a single bean as all the requests / invocations would have its own thread ; then what is the need to pool a few instances of bean.
 
Nitesh Kant
Bartender
Posts: 1638
IntelliJ IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is what the ejb spec(Section 7.8) has to say for Stateless session beans

The term �stateless� signifies that an instance has no state for a specific client. However, the instance
variables of the instance can contain the state across client-invoked method calls. Examples of such
states include an open database connection and an object reference to an EJB object.

So, essentially, its a business specific state that is forbidden to be maintained within a stateless session bean. One can store objects that might not be thread-safe for instance a reference to an Ejb object.
The whole idea is that the bean provider is completely saved from being aware of any multi-threaded code in the container. One can write ejbs as POJOs and still enjoy the benefits of scalability.
 
Jaikiran Pai
Sheriff
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There was a similar discussion sometime back at Why pool stateless session beans?
 
Rahul Bhattacharjee
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Nitesh for you reply.

My bad , I should have checked posts before posting a new question.
 
Rahul Bhattacharjee
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think I figured out one more reason for having the stateless session beans pooled.

The EJBObject acts as the proxy to the session beans and that holds many client information and container services are within this object only.

Say some business method need one such information before it can execute ,then it would need a handle to the EJBObject and that's not possible if we have only one bean object.
 
Nitesh Kant
Bartender
Posts: 1638
IntelliJ IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
any container specific data, eg: Transaction context, would always be as thread local variables, so it does not really matter whether it is a single instance or multiple.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!