Hi In Stateless session why do we need to implement ejbActivate(), and ejbPassivate() methods since its empty and doesnt maintain any state behalf of a client ? In Statefull Session Bean how cotainer maintain a conversational state for a client ? can any one explain briefly how it does ? how to identify a bean is a stateless or statefull programmatically instead of deployment descripter ? thanks in advance
In Stateless session why do we need to implement ejbActivate(), and ejbPassivate() methods since its empty and doesnt maintain any state behalf of a client ? Because, when you implement a session bean, your code doesn't care whether is stateless or stateful, you just implement the SessionBean interface when you write your bean. Now, if you look at the SessionBean interface you see that these two methods are declared there, so you must implement them, even if you put nothing in them (for stateless session bean. In Statefull Session Bean how cotainer maintain a conversational state for a client ? can any one explain briefly how it does ? thru passivation and activation. your bean is tied to a particular client, and will maintain its state by using these two methods and storing your instance (serializable) variables in a persistent storage, to keep resources and to wait until the client requests another business method. how to identify a bean is a stateless or statefull programmatically instead of deployment descripter ? Did you mean that if you look at a bean code, how can you say whether it's statless or stateful? hmm, stateless session beans have only a single ejbCreate() method, that takes no parameters. This is because stateless are *not* tied to any client. Stateful session beans can have multiple overloaded ejbCreate() methods. passivate/activate wouldn't do it, since you can put code in your stateless methods if you want, it just not going to be executed. hope it helps
I'm not going to be a Rock Star. I'm going to be a LEGEND! --Freddie Mercury
Joined: Jun 25, 2002
Thanks Andres. one more doubt. how can a ejb container match a bean with a purticular client after ejbActivation() ? there could be many clients can access statefull session bean. how does a ejb container identifies a purticular bean instance to purticular client ? pls give me in detail. thanks.
While ejbPassivate() callback; 1. release all the resources like db connections, socket connections etc. 2. storing object state in secondary storage device like hard disk, db. definately with client/session id.***** while ejbActivate() callback; 1. restoring the released resources 2. setting state values to bean based on client/seesion id. (container can set values(recreation of state) to any bean available in the pool (mostly least used) or can create new instance as per need.) developer need not to vary about ejbActivate()/ejbPassivate(); unless you need to manage resources to release/restore. And I beleive state management is duty of container.***** Please correct me if I am missing something. [ January 09, 2004: Message edited by: sanjeev mehra ]