2

By definition, Stateful EJBs retain state between calls, while Stateless beans don't.

My app is organized as follows:

app.ear
   |-EJB
      |-Local Stateful bean
      |-Local Stateless bean
   |-WAR
      |-Servlet - injects the beans via @EJB and can trigger an EJB method

Both beans implement a common business interface with one method. Method is implemented as a simple int count++ with output to console.

Stateless bean clearly retains conversation scope with the caller - the Servlet. It accurately increments with every method call the Servlet makes. And Servlet is called multiple times from different browsers with different http sessions.

Why the state is preserved?

And another inconsistency - Both Stateful/Stateless EJBs are said to have their lifecycles begin when client invokes some of their methods for the first time. While i found this to be true for Stateless beans, the Stateful one's lifecycle began (@PostConstruct method got called) as soon as it's injected via @EJB - without any invocation of any of its methods.

hrs
  • 379
  • 4
  • 12

0 Answers0