Stateless and Stateful Enterprise Java Beans

后端 未结 7 2067
我在风中等你
我在风中等你 2020-11-28 17:52

I am going through the Java EE 6 tutorial and I am trying to understand the difference between stateless and stateful session beans. If stateless session beans do not retain

7条回答
  •  挽巷
    挽巷 (楼主)
    2020-11-28 18:22

    Stateless and stateful in this context don't mean quite what you might expect.

    Statefulness with EJBs refers to what I call conversational state. The classic example is a flight booking. If it consists of three steps:

    • Reserve seat
    • Charge credit card
    • Issue Ticket

    Imagine each of those is a method call to a session bean. A stateful session bean can maintain this kind of conversation so it remembers what happens between calls.

    Stateless session beans don't have such capacity for conversational state.

    Global variables inside a session bean (stateless or stateful) are something else entirely. Stateful session beans will have a pool of beans created (since a bean can only be used in one conversation at a time) whereas stateless sesion beans will often only have one instance, which will make the global variable works, but I don't think this is necessarily guaranteed.

提交回复
热议问题