1

"Stateful: These beans can hold client state across method invocations. This is possible with the use of instance variables declared in the class definition. The client will then set the values for these variables and use these values in other method calls."

What does maintaining state across method calls mean ?

sorry for the noobness of my question.

lego.warrior
  • 342
  • 3
  • 16

2 Answers2

0

Statefullness is bad when it comes to concurrency. For Example you have one Statefull Bean, UserRegistrationBean which stores email then if two users try to register at the same time in a race condition one user overwrite the other one's email.

Statefullness requires synchronized access to the state which is costly.

shazin
  • 21,379
  • 3
  • 54
  • 71
0

You can think of it as the HttpSession on a web application. What you save on HttpSession is available across different requests to the web server. Likewise what you store as class variables in a session EJB is available across different method invocations done on the same session EJB.

Refer:

Lookup returns new instance of Stateful session bean http://www.javaworld.com/article/2071724/java-web-development/ejb-fundamentals-and-session-beans.html

Community
  • 1
  • 1
Dev Blanked
  • 8,555
  • 3
  • 26
  • 32
  • if it's not too much trouble, could you show me how to do a look up on a stateful session bean. – lego.warrior Dec 23 '14 at 04:56
  • @lee i've added some references. Look up is important in the case of entity ejb's. since it happens via ID. For session EJB's client has to use the same reference during the interaction. – Dev Blanked Dec 23 '14 at 05:12