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)?
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.