My original problem was: EJB3 + Struts2. Struts create new session bean for each request even if it is stateful.
Struts doesn't do anything by itself, it only does what you tell him to do. And I suspect that you're just misusing things. Showing some code to illustrate the problem might help.
Now I discover that JSF2 reuse the same session bean for each request even if it is stateless.
This is not true in general, you can get any instance of a stateless session bean (SLSB). And even if for some reasons you get the same instance in your particular situation (maybe because of the beans pool configuration), this shouldn't be an issue at all when using SLSB, you should not care of what instance you get and certainly not rely on the state of instances (since they're stateless).
Back to your question, I suspect that you're misusing SLSB and expecting things that are not true:
- Don't expect to get newly initialized instances between calls, that's not what stateless means.
- Actually, don't expect anything about the instance you'll get.
- Don't rely on the state of a SLSB instance (they are stateless, you're not supposed to rely on state).
- Don't rely on instance variable between remote calls.
- Actually, avoid using instance variables, there is probably no need for them.
Related questions