WSDL2JAVA(使用XMLBean绑定选项)是否通过Axis2 1.5.4线程安全生成存根(stub)?Axis2生成的存根是线程安全的?
其实我已经为我通过多线程调用的Web服务创建了一个存根。我已经配置了自己的MultiThreadedHttpConnectionmanager
并设置了HTTPConstants.REUSE_HTTP_CLIENT
,但我在每次调用后都会看到stub._getServiceClient().cleanupTransport
中的一些NullPointerException。
有时线程也挂起。
同时我注意到,在Web Service操作方法中生成的Stub中,cleanup()在finally块中已被调用。事后我不应该打电话给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);
与此同时,在生成的存根,我注意到,清理已经被称为:
finally {
_messageContext.getTransportOut().getSender().cleanup(_messageContext);
}
任何建议将是很大的帮助。谢谢。
这就是关键:如果没有明确指出某件事是线程安全的,那么就假设它不是。 – 2014-09-01 20:40:50