读者:架构设计师、开发人员
产品:websphere application server
版本:3.0.2.x、3.5.x、4.0
平台:全部
关键字:servlet、jsp、ejb、有状态会话bean
主题:ejb、性能、servlet 和 jsp
摘要
当企业 java bean(ejb)客户机不再需要有状态会话 bean 时,该客户机应该显式地将它从容器中除去。通过这样做,应用程序可以减少对钝化(passivation)的需要、最小化容器开销和提供更高级的性能。如果不显式地除去它们,容器对许多有状态会话 bean 的管理将耗费资源。
建议
有状态会话 bean 的实例与特定客户机有密切关系。它们将保持在容器中,直到由客户机显式地除去它们,或者当它们超时时由容器除去为止。同时,容器可能需要将非活动的有状态会话 bean 钝化到磁盘。这需要容器的开销并对应用程序构成了性能打击。如果随后应用程序需要钝化的会话 bean,容器通过从磁盘恢复该 bean 来激活它。
通过在完成使用时显式地除去有状态会话 bean,应用程序将减少对钝化的需求,使容器开销最小化并改进性能。通过显式地除去有状态会话 bean,您不必依赖于超时值。
当完成使用时显式地除去有状态会话 bean
import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.naming.*;
import com.ibm.uxo.ejbs.*;
public class bestpracticesservlet extends httpservlet {
bestpracticeshome ssehome = null;
public void init(servletconfig config) throws servletexcpetion {
super.init(config);
try {
ssehome = ejbhomecache.getinstance().getmbhhome();
}
catch(exception e) {
throw new servletexception("init error: " + e.getmessage(),e);
}
}
public void doget(httpservletrequest request, httpservletresponse response)
throws servletexception, ioexception {
bestpractices ssmgr = null;
try {
ssmgr = ssehome.create(1);
ssmgr.somebunchofmethods();
ssmgr.remove(); // explicitly remove when done!
}
catch (exception e) {
e.printstacktrace();
}
}
}
应被取代的方法
application server 可以使用超时值来处理除去您的有状态会话 bean。但是,当管理这些资源时,您可能体验到下降的性能,这取决于应用程序。
参考资料
websphere application server development best practices for performance and scalability
作者
姓名:harvey w. gunther
职务:高级性能分析师
部门:websphere 产品开发
公司:ibm
地点:美国北卡罗莱那州罗利(raleigh)
电子邮件:hgunther@us.ibm.com
Java Asp PHP .Net XML C/C++ CGI VB Jsp J2ee J2se J2me EJB Servlet Tomcat Resin Struts Weblogic Eclipse ANT GUI JMS Web servise IDEA Webphere Hibernate Spring Jboss Applet Swing Socket Javamail Perl Ajax P2P 安全 模式 框架 测试 开源 游戏
Windows XP Windows 2000 Windows 2003 Windows Me Windows 9.x Linux UNIX 注册表 操作系统 服务器 应用服务器