Axis2设置连接超时的正确方法是什么,因此超时

时间:2017-09-08 04:17:09

标签: java axis2

我有一个Java程序,它使用Axis2来使用Web服务。现在我想为该客户端设置连接超时和套接字超时。

我搜索过并发现有两种方法可以做到这一点。

第一种方法

https://singztechmusings.wordpress.com/2011/05/07/how-to-configure-timeout-duration-at-client-side-for-axis2-web-services/

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); 

0 个答案:

没有答案