So I had a discussion about stateless session beans and them containing state.
Coming from spring, I expected stateless to mean no state what so ever. This is because the default scope for beans in spring is Singleton. This allows beans to be shared (and wired) on application startup, ensuring that no real bean pool management is necessary. The container decides to use separate beans for injection, or all the same, since there is no real 'pool' to speak of.
Compare this to EJB, which has a stateless session bean. This compares with a stateful session bean.
A stateful session bean contains the state through the entire session. A stateless session bean does not.
However, a stateless session bean can contain state. Stateless session beans are request scoped, meaning that any state they have they can access within the request.
This, of course, comes from EJB's Stateful and Stateless EJB's of old, where it was made that way.
Spring made sure that stateless = no state, under no circumstance. Hence, my confusion.
Live and learn in EJB-land!...
Addendum
What still remains, of course, is that beans are recycled between requests. So if you add data to a stateless session bean, it should be invalated/cleared after use.
Usually, when a stateless EJB contains state, it a database connection, or something like that. (although we can inject that these days). Having temporary state in there can screw up the working of your EJB when that state is used in another session after the bean is recycled...
So, 'still' keep your stateless session bean as stateless as possible...
Coming from spring, I expected stateless to mean no state what so ever. This is because the default scope for beans in spring is Singleton. This allows beans to be shared (and wired) on application startup, ensuring that no real bean pool management is necessary. The container decides to use separate beans for injection, or all the same, since there is no real 'pool' to speak of.
Compare this to EJB, which has a stateless session bean. This compares with a stateful session bean.
A stateful session bean contains the state through the entire session. A stateless session bean does not.
However, a stateless session bean can contain state. Stateless session beans are request scoped, meaning that any state they have they can access within the request.
This, of course, comes from EJB's Stateful and Stateless EJB's of old, where it was made that way.
Spring made sure that stateless = no state, under no circumstance. Hence, my confusion.
Live and learn in EJB-land!...
Addendum
What still remains, of course, is that beans are recycled between requests. So if you add data to a stateless session bean, it should be invalated/cleared after use.
Usually, when a stateless EJB contains state, it a database connection, or something like that. (although we can inject that these days). Having temporary state in there can screw up the working of your EJB when that state is used in another session after the bean is recycled...
So, 'still' keep your stateless session bean as stateless as possible...
Reacties
Een reactie posten