When is the stateful session bean destroyed?
I am new to ejbs and I want to know whether a stateful session bean will be destroyed or not. I injected a stateful session bean in my servlet. Even after 30min I see that the bean is active. I am using jboss eap 6.0. I believe that HttpSession has nothing to do with a stateful session bean. I invalidated the HttpSession to make sure that HttpSession has nothing to do with the statful session bean. So what if my application has many users and for each user if I create a new bean, the performance of my server is brought down. How does the container manage stateful session beans. When is a bean removed or destroyed?
I read this post and few others. But I did not get clarity.
A Stateful Session Bean is not client contextualized and must be destroyed explicitly within your code.
1) The SFSB must define a method annotated by @Remove
:
@Stateful
@Local(ILocalQuiz.class)
public class QuizBean implements ILocalQuiz{
//...
@Remove
@Override
public void end() {
System.out.println("QuizBean instance will be removed..");
}
}
2) The SessionScoped bean must call explicitly end()
method :
public void cleanUp(){
System.out.println("Cleaning up before destroying the SessionScoped bean.");
quizProxy.end();
}
@SessionScoped
annotation only makes sense in a web context, outside a web context you should assume that your @SessionScoped
will be ignored and your stateful EJB
will behave like an old regular stateful ejb, and you shouldn't inject a stateful resource (old regular stateful EJB) into a stateless one (Servlet), in that case the scope of your stateful ejbs will depend on the scope of the instances of your servlet, and the java servlet spec. doesn't strictly require the container to create a servlet instance per session or request, as a matter of fact, some containers will use a single instance of your servlet to serve all clients, in which case you'd end up having this ugly situation where a single stateful ejb instance would be serving all your clients, check this out,
Stateful session beans unexpected behaviour when packaged in a war and packaged in an ear->jar
链接地址: http://www.djcxy.com/p/18776.html上一篇: @extends('布局')laravel。 刀片模板系统似乎不起作用
下一篇: 有状态会话Bean何时销毁?