This week's giveaway is in the EJB and other Java EE Technologies forum. We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line! See this thread for details.
Do we have to make all the member variables stateless explicitly or container manages their state ?
There is nothing like making member variables stateless.
Stateless in case of Stateless session beans means that the client will never know which instance from the instance pool of the stateless session bean is serving the request. If you try maintain state (For e.g. Name of the Client) using an instance variable in SLSB, then you will never have guarantee that your next method call will be handled by the same SLSB instance that served you earlier. I hope that I am helping you to understand this.
Let me try to illustrate this as well using a Pseudo Code.
1) Client invokes SLSB.setClientName()
2) SLSB.method1 -> sets some instance variable of SLSB -> this.clientname - "amit"
3) Client invokes SLSB.getClientName() - This may or may not return you the expected value i.e. "amit" which was set in #2.
Please note that SLSB generally exposes the business functions, I just took help of set/get as it is easier to understand statelessness using this.