| Author |
Lifetime of a stateful session bean
|
Uli Hofstoetter
Ranch Hand
Joined: Nov 24, 2006
Posts: 57
|
|
Hello, i am just starting with EJB3 and have a (little) problem with a stateful session bean running under Glassfish (V2 UR1). Here is the Bean Class: The bean is called from a servlet and subsequent calls to the servlet from my local Firefox give Hello World (1) Hello World (2) ... So fine until here. When i switch to Internet Explorer and call the servlet (which should start a new session, as i understand), the counter does not start again, but continues. Same behaviour when the HttpSession expires (verified with a session listener). The next call to the servlet creates a new HttpSession, but the counter does not restart, but continues. Did i really totally missunderstand stateful session beans, or should there be a new stateful session bean, when a new HttpSession starts? Regards, Uli [ April 15, 2008: Message edited by: Uli Hofstoetter ]
|
SCEA5, Certified ScrumMaster
|
 |
Jeanne Boyarsky
internet detective
Marshal
Joined: May 26, 2003
Posts: 26496
|
|
Uli, Welcome to JavaRanch! Is the bean an instance variable in the servlet? If so, the servlet still has a reference to the first browser's associated session bean. And as multiple users share a servlet, the second browser could see that. The stateless session bean itself should work as you describe if called properly.
|
[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
|
 |
Uli Hofstoetter
Ranch Hand
Joined: Nov 24, 2006
Posts: 57
|
|
Hello Jeanne and thanks for the welcome. You exactly described the "problem", which is not really a problem, but the behaviour. I found out by now that dependency injection with servlets and stateful session bean does not work due to the multithreaded nature of servlets. To use a stateful session bean in a servlet, the bean instance has to be looked up via JNDI and then stored in the HttpSession. Regards, Uli
|
 |
 |
|
|
subject: Lifetime of a stateful session bean
|
|
|