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)?
Use @Stateful annotation to signify it a stateful bean.
Session beans typically have the following characteristics: Represent a conversation between client and server. Execute on behalf of single client. They cannot be shared by more than one client at the same time.
There are 3 important annotations used in stateless session bean: @Stateless. @PostConstruct. @PreDestroy.
A stateful session bean is a session bean that maintains conversational state. Stateful session beans are useful for conversational sessions, in which it is necessary to maintain state, such as instance variable values or transactional state, between method invocations.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With