使用axis2构建webservice时客户端内存不断增长导致应用服务器频繁重启的解决方案
2010-01-14 21:31
645 查看
使用axis2构建webservice时,发现系统运行一段时间后客户端的内存使用一直不断增高,导致应用服务器无法承受而重启,这里提供了一种解决方案。
原因分析:客户端以stub方式请求服务,stub对象是一个非常重量级的对象,每次客户端向服务端请求服务时,stub对象不断被创建,占用大量系统资源
解决方案:考虑到所有的客户端stub都继承自org.apache.axis2.client.Stub类,考虑使用简单工厂模式+简单的对象池来提供stub对象实例,这样只需首次需要stub对象时实例化一次,以后需要用的时候从stub对象池中取得,工厂类本身做成单例模式。
代码实现:
取stub对象只要如下代码:
原因分析:客户端以stub方式请求服务,stub对象是一个非常重量级的对象,每次客户端向服务端请求服务时,stub对象不断被创建,占用大量系统资源
解决方案:考虑到所有的客户端stub都继承自org.apache.axis2.client.Stub类,考虑使用简单工厂模式+简单的对象池来提供stub对象实例,这样只需首次需要stub对象时实例化一次,以后需要用的时候从stub对象池中取得,工厂类本身做成单例模式。
代码实现:
public class StubFactory{ //从配置文件中取客户端应用context的绝对路径 public static final String path=ServiceConfig.getPath(); //从配置文件中取服务url public static final String serviceUrl=ServiceConfig.getServiceUrl(); private static Map map=new HashMap();//这里可以是一个同步的Map,也可以直接用Hashtable private static ConfigurationContext configurationContext=null; private static StubFactory stubFactory=new StubFactory(); private StubFactory(){}; static{ try{ configurationContext=ConfigurationContextFactory.createConfigurationContextFromFileSystem(path+"/WEB-INF",path+"/WEB-INF/conf/axis2.xml"); }catch(AxisFault e){ e.printStackTrace(); } } public Stub getStub(String type){ Stub stub=null; if(map.get(type)==null){ stub=(Stub)this.createStub(type); map.put(type,stub); } return (Stub)map.get(type); } private Stub createStub(String type){ Stub stub=null; String targetEndpoint=null; try{ if("SearchServiceStub".equals(type)){ targetEndpoint=serviceUrl+"services/SearchService.SearchServiceHttpSoap12Endpoint/"; stub=new SearchServiceStub(configurationContext,targetEndpoint); } if("CalculateServiceStub".equals(type)){ targetEndpoint=serviceUrl+"services/CalculateService.CalculateServiceHttpSoap12Endpoint/"; stub=new CalculateServiceStub(configurationContext,targetEndpoint); } if("MessageServiceStub".equals(type)){ targetEndpoint=serviceUrl+"services/MessageService.MessageServiceHttpSoap12Endpoint/"; stub=new MessageServiceStub(configurationContext,targetEndpoint); } }catch(Exception e){ e.printStackTrace(); } return stub; } public static StubFactory getInstance(){ return stubFactory; } }
取stub对象只要如下代码:
SearchServiceStub stub=(SearchServiceStub)StubFactory.getInstance().getStub("SearchServiceStub");
相关文章推荐
- 使用axis2构建webservice时客户端内存不断增长导致应用服务器频繁重启的解决方案
- 使用axis2构建webservice时客户端内存不断增长导致应用服务器频繁重启的解决方案 .
- 使用AXIS2构建WebService服务器
- WebServices学习2——使用Eclipse+Axis2构建Web Service应用(客户端无需生成Stub方式)
- 使用Eclipse+Axis2构建Web Service应用(客户端无需生成Stub方式)
- 使用CXF构建webservice和rest应用
- SharpStreaming项目开发纪实:构建基于RTSP协议的服务器及客户端应用(二)——服务器的业务代码实现
- 关于K3中间层注册后,服务器注销或锁定状态,客户端无法使用的解决方案
- 关于socket应用:一个不断监听一个进程的服务器以及发送信息的客户端 TCP的三次握手和四次挥手
- 使用命令wsimport构建WebService客户端
- 使用Spring构建RMI服务器和客户端
- Outlook客户端无法发送附件,频繁与Exchange服务器断开现象解决方案
- 使用命令wsimport构建WebService客户端
- 使用Axis2开发webservice服务端接口+axis开发的客户端调用
- 在EclipseJEE(mars)中使用Axis2开放WebService服务端接口和建立WebService客户端
- 用AXIS2发布WebService的方法 使用eclipse插件生成服务端和客户端
- SharpStreaming项目开发纪实:构建基本的服务器及客户端应用(三)——准备知识(多线程编程)
- 使用Axis2来构建Web Service客户端
- 使用Axis2编写webservice客户端,服务端
- 异常信息:CLR无法从COM 上下文0x645e18 转换为COM上下文0x645f88,这种状态已持续60秒。拥有目标上下文/单元的线程很有可能执行的是非泵式等待或者在不发送 Windows 消息的情况下处理一个运行时间非常长的操作.这种情况通常会影响到性能,甚至可能导致应用程序不响应或者使用的内存随时间不断累积