This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
I'm getting confused by something about stateless session beans. The spec and books talk about creating multiple instances of stateless session beans, keeping inactive stateless session beans in a bean pool, and so on. If a stateless session bean truly has no state (i.e., no instance variables), there is never a need to create more than one instance of the bean. I presume that the point of confusion here is that stateless session beans are allowed to have instance variables and state, but that this state only persists for the duration of one call from a bean client. Can someone confirm that for me?
Multiple instances of stateless session bean can service multiple client requests at one time. Stateless means that they do not carry any state from one method invocation to another and hence any client thread can use them
I'm not sure those responses really solve my confusion. To put it another way, does the spec guarantee that while one client is invoking a method on a stateless session bean, no other client will invoke a method on that session bean? That would mean it would be safe to have state stored in instance variables so long as that state didn't persist past a single call from a client.
Bill, EJB's are single threaded, hence only one method invocation can be executed on an EJB at a time. Therefore, as previously mentioned the Container can spawn multiple instances of stateless session beans to handle multiple client invocations. The term stateless simply means theres no affinity between method invocations from a client to stateless sb. But, just like any java object its can have state, but its not associated to any single client. hope this helps. Rowan