This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes EJB and other Java EE Technologies and the fly likes Stateless & Stateful Session Bean Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Stateless & Stateful Session Bean" Watch "Stateless & Stateful Session Bean" New topic
Author

Stateless & Stateful Session Bean

saravana kumar
Ranch Hand

Joined: Jun 25, 2002
Posts: 72
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
Andres Gonzalez
Ranch Hand

Joined: Nov 27, 2001
Posts: 1561
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
saravana kumar
Ranch Hand

Joined: Jun 25, 2002
Posts: 72
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.
sanjeev mehra
Ranch Hand

Joined: Feb 12, 2001
Posts: 93
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 ]
 
jQuery in Action, 2nd edition
 
subject: Stateless & Stateful Session Bean
 
Similar Threads
Design Decision help needed
Confused about STFL and STLS beans
servet/jsp to stateless ejb/statefull ejb
Bean Managed Vs Container managed
Instance Variables State