Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Stateless Session bean : Multiple Clients reference

 
chandrasekhar muvvala
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can Multiple Clients can have a reference to the same bean? w.r.t to Stateless Session Beans.
I found the answers can be both : YES & NO
YES because, can refer but not at the same time.


How to justify this question, what is the correct answer?
 
Valentin Crettaz
Gold Digger
Sheriff
Posts: 7610
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually, when a client invokes a method on a stateless session object, the container takes one session bean out of the pool and invokes the method on it. When the call returns, the container might put the instance back in the pool or use it for servicing other incoming calls. The bottom line is that at any time, only one client is executing a method of given session bean instance. So, yes, multiple clients may have a reference to "the same" stateless session bean, but due to the nature of stateless session bean, you have no idea how the container decides to manage those reference, and thus, you have no idea whether the references the client has all point to the same stateless session bean. Actually, you don't even have to care about the instance that is executing your calls since the beans are stateless, and thus, they all do the same job... Does this make sense to you?
 
Balaji Natarajan
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
me too have the same doubt.

From the above post may i conclude that the business methods of a stateless session bean should not depend on the instance variables of the bean and it should depend only on the input parameters.

Balaji.
 
Natarajan Shankar
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Even EJB spec doesn't recommend to create instance variable in the statless bean. So it must depends on input parameter.
 
Valentin Crettaz
Gold Digger
Sheriff
Posts: 7610
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Stateless session beans may declare instance variables, of course. The only requirement is that those variables should not be used to store client-specific data since they are supposed to be stateless... Examples of instance variables are database connections, etc...
[ June 30, 2004: Message edited by: Valentin Crettaz ]
 
Balaji Natarajan
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks Valentin and Shankar its clear now.

Balaji
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic