Can stateful session beans cause a leak when no @Remove annotated method is called?
Asked Answered
Z

2

6

I have a JSF application that, in a managed bean, calls business logic from a remote stateful session bean (EJB 3.0).

Right now there is a HttpSessionListener that calls a @Remove annotated method on that stateful session bean, so that the stateful session bean can be removed by the container as soon as the HttpSession gets destroyed.

Now I wonder what happens if I don't call that @Remove annotated method and the HttpSession gets destroyed. The client of the stateful session bean does no loger exist then. Will the container ever remove the stateful session bean? Or will it exist forever causing some kind of leak (memory / disk)?

Zwart answered 4/9, 2012 at 9:19 Comment(0)
B
9

Yes, the container will remove the unused stateful session bean when it gets timed-out. Anyway, calling the @Remove annotated method when the bean's state is no longer needed is the pattern to follow.

The removal timeout of stateful session beans can be set in your application server's settings.

Bisson answered 4/9, 2012 at 9:30 Comment(0)
M
4

If @Remove annotation is not specified stateful bean will stay in the context till the timeout time specified. It doesn't directly call a leak but if you are not managing dependencies correctly and there are some references left then you can have a potential memory leak. So it is advisable to use @Remove annotation.

Mysterious answered 4/9, 2012 at 9:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.