Stateful vs Stateless Session beans-Differences January 25, 2008Posted by Coolguy in J2EE, Java.
State: Stateful maintains information across sessions while stateless doesn’t. If a transaction would span over two or more bean executions you should use stateful session bean, otherwise use stateless session bean. Stateful beans remember state between
Scalability: Stateful beans hurt scalability.
Pooling: Stateless beans, by nature, need not know their clients once the remote business method returns. These beans can therefore be bean-pooled. On the other hand stateful session beans may be requested back(with previous state) by a client using the javax.ejb.Handle reference that the client may have retained. In this case, the bean will need to be re-instated entirely. These beans therefore can only be instance-pooled and never shared between clients.
Passivation: Stateless beans are not passivated. SFSB’s are activated/passivated.
In ejb-jar.xml ‘session-type’ attribute determines whether the bean is stateful or stateless.
Stateful beans import:
Stateless beans import: