EJB 3.0 Stateful session bean shared between Servlet's
Hello
I have a bit of a noob question regarding Stateful sessions beans.
I am wanting to know if there is a way that I can share an instance of a session bean between multiple HttpServlet instances?
I am sending XML messages from a mobile J2ME application, there will be several http POST's made from the mobile client to the server. I would like these multiple POST's to be passed from the handling servlet instance to the same uniquely identified single stateful session bean instance (i can then @Remove the stateful bean when I have finished my several requests).
I would greatly appreciate any tips anyone could give me.
[658 byte] By [
tinnya] at [2007-11-27 6:54:45]

# 1
If the multiple requests are part of the same HTTP Session, then the easiest approach
is to store the SFSB reference itself in the HttpSession.The Java EE spec requires that this be
supported.
If not, your only option is to maintain the association yourself by creating a unique id for each
conversation and storing that id along with the SFSB reference in the ServletContext. Then you'll
need to pass the id in along with each invocation to retrieve the appropriate SFSB reference.
ksaksa at 2007-7-12 18:29:53 >

# 2
> If not, your only option is to maintain the
> association yourself by creating a unique id for
> each
> conversation and storing that id along with the SFSB
> reference in the ServletContext. Then you'll
> need to pass the id in along with each invocation to
> retrieve the appropriate SFSB reference.
Thanks for your reply.
Will I always be presented with the same ServletContext instance? Even if the time between requests might be many minutes? Where can I learn more about how to use the ServletContext?
Thanks!
tinnya at 2007-7-12 18:29:53 >

# 3
There is one ServletContext per .war, so it will be available as long as the web app is running.
There's some good information in the JavaDoc :
http://java.sun.com/javaee/5/docs/api/
There's also some coverage in the Java EE tutorial :
http://java.sun.com/javaee/5/docs/tutorial/doc/
ksaksa at 2007-7-12 18:29:53 >
