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

Haq*_*nus 4 java axis2 code-generation wsdl2java thread-safety

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

实际上我已经为一个Web服务创建了一个Stub,我通过多个线程调用它.我已经配置了自己的MultiThreadedHttpConnectionmanager设置,HTTPConstants.REUSE_HTTP_CLIENT但我看到一些NullPointerExceptions 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);
Run Code Online (Sandbox Code Playgroud)

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

   finally {
            _messageContext.getTransportOut().getSender().cleanup(_messageContext);
        }
Run Code Online (Sandbox Code Playgroud)

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

小智 7

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

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

提到:

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

问题本身已关闭,Won't Fix状态和以下注释:

Axis2存根不是线程安全的.正如Deepal指出这是设计的.

当时就是这样做的.

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

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

  • 这就是重点:如果没有明确说明某些东西是线程安全的,那么假设它不是. (2认同)