Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

instance variables in stateless session beans

I have read this post and it doesn't answer my question. Stateless session bean with instance variables I am reading the JEE5 tutorial and on this page it states http://download.oracle.com/javaee/5/tutorial/doc/bnbly.html " Clients may, however, change the state of instance variables in pooled stateless beans, and this state is held over to the next invocation of the pooled stateless bean "

I don't agree with this.. coz i thought keeping 'any' kind of state across invocations of different instance of beans was something you need 'stateful' session beans for.

Please help me understand this thx in advance Rooban

like image 600
Robin Bajaj Avatar asked Apr 13 '11 01:04

Robin Bajaj


1 Answers

In EJB the distinction between "stateful" and "stateless" refers to conversational state, not simply Java object state (that is, any use of instance fields).

From Wikipedia:

In a stateful session bean, the instance variables represent the state of unique client-bean sessions. The interaction of the client with bean is called as conversational state.

The classic example is that of a shopping cart for an ecommerce application. You'd use a SFSB to store the "cart" object because it needs to maintain conversational state between requests.

On the other hand:

A stateless session bean is an object that does not have an associated conversational state, but may have instance state. It does not allow concurrent access to the bean. The contents of instance variables are not guaranteed to be preserved across method calls. All instances of a stateless session bean should be considered identical by the client.

Related questions

  • Stateless and Stateful Enterprise Java Beans
  • Stateful EJBs in web application?
  • Correct usage of Stateful Beans with Servlets
  • Static vs Instance members in Stateless EJBs
  • Why use stateful session beans?
like image 101
Matt Ball Avatar answered Sep 28 '22 12:09

Matt Ball