Axis2生成的Stub是线程安全的吗? [英] Axis2 generated Stubs are thread-safe?

查看:363
本文介绍了Axis2生成的Stub是线程安全的吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Are the Stubs generated by WSDL2JAVA (using XMLBeans binding option) through Axis2 1.5.4 thread-safe?

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

Actually I have created one Stub for a Web Service that I am invoking through multiple threads. I have configured my own MultiThreadedHttpConnectionmanager and set the HTTPConstants.REUSE_HTTP_CLIENT as well but I am seeing some NullPointerExceptions in stub._getServiceClient().cleanupTransport that I call after each invocation.

有时线程也会挂起。

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

At the same time I noticed that in the generated Stub in the Web Service operation method, cleanup() is called already in the finally block. Should I not call stub._getServiceClient().cleanupTransport myself afterwards?

我的代码:

        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:

Meanwhile in the generated stub, I noticed that cleanUp is already been called:

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

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

Any suggestion would be greatly helpful. Thanks.

推荐答案

前一段时间我看过Axis2时,我也遇到了与线程安全相关的问题。

When I looked into Axis2 some time ago, I also had thread-safe related questions about it.

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

Finding information about Axis2's thread safety was difficult, but I finally ended up with the following Jira issue: https://issues.apache.org/jira/browse/AXIS2-4357

这是提到:


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

Axis2 client side is not thread safe, and which was the case from the beginning of the project [...] use different stubs for different threads [...]

问题本身以关闭不会修复状态并带有以下注释:

The issue itself is closed with a Won't Fix status and with the following note:


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

Axis2 stubs are not thread safe. As Deepal pointed out this is by design.

那个时候对我有用。

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

Basically you need to use one stub per thread or you can use a stub pool as (if I remember correctly) the stubs can be reused (but still need to use one stub per thread to avoid any issues). Other seem to have used stub pools with success (see related SO question here).

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

One advice I usually follow regarding thread safety is: If it is not explicitly stated that something is thread safe, then assume it is not.

这篇关于Axis2生成的Stub是线程安全的吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆