conversational state of session beans

后端 未结 3 1052
天涯浪人
天涯浪人 2021-01-05 03:23

I\'m reading a book on Java EE 6 and I met with the following parts:

\"Stateless: The session bean contains no conversational state between methods, and any ins

3条回答
  •  佛祖请我去吃肉
    2021-01-05 03:35

    A real world example of a conversational state would be Shopping Cart. A user can add several items to shopping cart one by one and then call checkout. All the added times would be there

    Suppose the cart is stateful, i.e. it will keep the conversational state.

    cart.add(item1);  // suppose cart keep tracks of item by adding it to ArrayList
    cart.add(item2);
    
    cart.checkOut();    // at this stage both item1 and item2 would be there in ArrayList.
    

    If the cart is stateless, each call will be independent of previous ones and at checkout it can have nothing.

    For your second point The distinction is necessary due to differences in behaviour of both beans. Maintaining state require resources therefore stateful beans are not as scalable as stateless beans.

提交回复
热议问题