Axis2生成的Stub是线程安全的吗?

是通过Axis2 1.5.4线程安全的WSDL2JAVA(使用XMLBeans绑定选项)生成的存根吗?

实际上我已经为我通过多个线程调用的Web服务创建了一个Stub。 我已经配置了我自己的MultiThreadedHttpConnectionmanager并设置了HTTPConstants.REUSE_HTTP_CLIENT ,但我在stub._getServiceClient().cleanupTransport看到了一些NullPointerExceptions stub._getServiceClient().cleanupTransport每次调用后调用的stub._getServiceClient().cleanupTransport

有时线程也会挂起。

同时我注意到在Web Service操作方法中生成的Stub中,在finally块中已经调用了cleanup()。 我不应该之后调用stub._getServiceClient().cleanupTransport吗?

我的代码:

  httpConnMgr = new MultiThreadedHttpConnectionManager(); HttpConnectionManagerParams params = httpConnMgr.getParams(); if (params == null) { params = new HttpConnectionManagerParams(); } params.setDefaultMaxConnectionsPerHost(numberOfThreads); httpConnMgr.setParams(params); HttpClient httpClient = new HttpClient(httpConnMgr); service = new Service1Stub(this.endPointAddress); service._getServiceClient().getOptions() .setTimeOutInMilliSeconds(this.timeOut); service._getServiceClient().getOptions() .setProperty(HTTPConstants.REUSE_HTTP_CLIENT, Boolean.TRUE); service._getServiceClient().getOptions() .setProperty(HTTPConstants.AUTO_RELEASE_CONNECTION, Boolean.FALSE); service._getServiceClient() .getOptions() .setProperty(HTTPConstants.SO_TIMEOUT, (int) (this.timeOut)); service._getServiceClient() .getOptions() .setProperty(HTTPConstants.CONNECTION_TIMEOUT, (int) (this.timeOut)); service._getServiceClient().getServiceContext().getConfigurationContext() .setProperty(HTTPConstants.CACHED_HTTP_CLIENT, httpClient); 

同时在生成的存根中,我注意到已经调用了cleanUp:

  finally { _messageContext.getTransportOut().getSender().cleanup(_messageContext); } 

任何建议都会有很大帮助。 谢谢。

当我在不久前看到Axis2时,我也遇到了与线程安全相关的问题。

找到有关Axis2的线程安全的信息很困难,但我最终得到了以下Jira问题: https : //issues.apache.org/jira/browse/AXIS2-4357

提到:

Axis2客户端不是线程安全的,从项目开始就是这种情况[…]为不同的线程使用不同的存根[…]

问题本身Won't Fix状态关闭,并附带以下注释:

Axis2存根不是线程安全的。 正如Deepal所指出的那样,这是设计上的。

那个时候对我来说就是这样。

基本上你需要为每个线程使用一个存根,或者你可以使用存根池(如果我没记错的话)可以重用存根(但是仍然需要为每个线程使用一个存根以避免任何问题)。 其他似乎已经成功使用了存根池( 参见相关的SO问题 )。

我通常关于线程安全的一个建议是: 如果没有明确说明某些东西是线程安全的,那么假设它不是