我有一个Java程序,它使用Axis2来使用Web服务。现在我想为该客户端设置连接超时和套接字超时。
我搜索过并发现有两种方法可以做到这一点。
第一种方法
stub._getServiceClient().getOptions().setProperty(HTTPConstants.SO_TIMEOUT, new Integer(timeOutInMilliSeconds));
stub._getServiceClient().getOptions().setProperty(HTTPConstants.CONNECTION_TIMEOUT, new Integer(timeOutInMilliSeconds));
第二种方法
https://community.emc.com/docs/DOC-44893
MultiThreadedHttpConnectionManager multiThreadedHttpConnectionManager = new MultiThreadedHttpConnectionManager();
HttpConnectionManagerParams params = new HttpConnectionManagerParams();
params.setSoTimeout(timeOutInMilliSeconds);
params.setConnectionTimeout(timeOutInMilliSeconds);
multiThreadedHttpConnectionManager.setParams(params);
HttpClient httpClient = new HttpClient(multiThreadedHttpConnectionManager);
stub._getServiceClient().getServiceContext().getConfigurationContext().setProperty(HTTPConstants.CACHED_HTTP_CLIENT, httpClient);
有谁知道这两种方法有什么区别?
修改: 我还发现了以下用于设置超时的方法。混乱是最好的。 :(
stub._getServiceClient().getOptions().setTimeOutInMilliSeconds(180000);