Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Why have more than one stateless session bean?

 
Bill Pugh
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm getting confused by something about stateless session beans.
The spec and books talk about creating multiple instances of stateless session beans, keeping inactive stateless session beans in a bean pool, and so on.
If a stateless session bean truly has no state (i.e., no instance variables), there is never a need to create more than one instance of the bean.
I presume that the point of confusion here is that stateless session beans are allowed to have instance variables and state, but that this state only persists for the duration of one call from a bean client. Can someone confirm that for me?
 
Monmohan Singh
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Multiple instances of stateless session bean can service multiple client requests at one time. Stateless means that they do not carry any state from one method invocation to another and hence any client thread can use them
 
Pradeep bhatt
Ranch Hand
Posts: 8927
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moreover, SLSB avoid the costly creation and descrution of objects.
 
Bill Pugh
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure those responses really solve my confusion.
To put it another way, does the spec guarantee that while one client is invoking a method on a stateless session bean, no other client will invoke a method on that session bean? That would mean it would be safe to have state stored in instance variables so long as that state didn't persist past a single call from a client.
 
Rowan John
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bill,
EJB's are single threaded, hence only one method invocation can be executed on an EJB at a time. Therefore, as previously mentioned the Container can spawn multiple instances of stateless session beans to handle multiple client invocations.
The term stateless simply means theres no affinity between method invocations from a client to stateless sb. But, just like any java object its can have state, but its not associated to any single client.
hope this helps.
Rowan
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic