• Post Reply Bookmark Topic Watch Topic
  • New Topic

Http Session and stateful EJB state  RSS feed

 
Linwood Hayes
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I know how http session is maintained between server and client : when server creates a session, it uses either cookie or URL rewriting to send back JSESSION ID which tracks session. Now if there is another stateful EJB involved here. suppose client calls a servlet on application server, this application server creates a session and invokes a stateful EJB which may run on another remote server. How is the stateful session EJB state maintained and what is its relationship with the http session ? Is that state maintained "inside" the http session ? could that state be terminated while session is still alive ? when session is killed would that state be still alive ?

Any explanation ? Thanks
 
Claude Moore
Ranch Hand
Posts: 862
8
IBM DB2 Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The state of an Ejb is maintained by the Ejb itself. A stateful EJBs is an Ejb instance dedicated to a single client. This means that in a stateful Ejb, you can safely assume that the same instance will be used across different method invocations, so that you can have instance variables maintaining the 'state' of the object. For example, you could set with a method call a list of product items, with another call you may set the customer's info and with a third invocation you can write an order. This scenario would be impossible wit stateless Ejbs: there is no guarantee that the same instance will b responding to two consecutive invocations of service by the same client.
In the HTTP session is stored only a stub of the remote Ejb.The stub will take care to invoke remote methods on the Ejb, but they re actually two different things. When you are done with a Ejb, you should remove it explicitly.Honestly I don't know what happens if, for example, the webserver is shut down without a clean up. I presume that remote Ejbs will survive, but they won't be accessible anymore resulting in a garbage.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!