jump to navigation

Stateful vs Stateless Session beans-Differences January 25, 2008

Posted 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.

      Version 2.X:

      In ejb-jar.xml ‘session-type’ attribute determines whether the bean is stateful or stateless.


      Version 3.X

      Stateful beans import: import javax.ejb.Stateful

      Stateless beans import: import javax.ejb.Stateless



      No comments yet — be the first.

      Leave a Reply

      Fill in your details below or click an icon to log in:

      WordPress.com Logo

      You are commenting using your WordPress.com account. Log Out /  Change )

      Google+ photo

      You are commenting using your Google+ account. Log Out /  Change )

      Twitter picture

      You are commenting using your Twitter account. Log Out /  Change )

      Facebook photo

      You are commenting using your Facebook account. Log Out /  Change )

      Connecting to %s

      %d bloggers like this: