Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

java

ejb-3.0

ejb

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

like image 881
Sylar Avatar asked Sep 04 '12 09:09

Sylar


People also ask

Which of the following annotation is used in stateful session bean?

Use @Stateful annotation to signify it a stateful bean.

What are the 3 characteristics of a stateful session 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.

Which of the following annotations are used in stateless session bean?

There are 3 important annotations used in stateless session bean: @Stateless. @PostConstruct. @PreDestroy.

What is the function of stateful session bean?

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.


2 Answers

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.

like image 96
Csaba Avatar answered Sep 27 '22 23:09

Csaba


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.

like image 24
Bharat Sinha Avatar answered Sep 27 '22 23:09

Bharat Sinha