相关疑难解决方法(0)

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

是通过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)

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

java axis2 code-generation wsdl2java thread-safety

4
推荐指数
1
解决办法
6321
查看次数

通过 RMI 从本地计算机上的多个线程调用线程安全方法是否安全?

我有一些方法将通过 RMI 调用远程方法,如下所示:

/**
 * Implementation is supposed to be thread safe
 */
public interface Act extends java.rmi.Remote{
    String doSome() throws RemoteException;
}

public class SomeClass {
    private static final Act stub = (Act) Naming.lookup("/server/stub")

    public static void someMethodAccessedByMultipleThreads(){
        System.out.println(stub.doSome());
    }
}
Run Code Online (Sandbox Code Playgroud)

如果远程方法是线程安全的,那么someMethodAccessedByMultipleThreads多线程调用是否安全?

或者是否存在一些 RMI 线程/网络/其他问题?

java multithreading rmi

2
推荐指数
1
解决办法
1199
查看次数