当HttpClient级别的超时设置已经完成时,为HttpGet和HttpHead方法设置超时是否更好?

时间:2012-12-05 01:49:16

标签: java timeout httpclient

我们有以下代码与我们的网站交谈,我们在HttpClient级别设置了超时阈值,以确保“我们不会等待很长时间才能获得响应。”。代码是否足以满足上述要求?我们还需要为HttpHead方法设置额外的超时设置吗?

        HttpClient httpclient = new DefaultHttpClient();
        // the time it takes to open TCP connection.
        httpclient.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, this.timeout);

        // timeout when server does not send data.
        httpclient.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT, this.timeout);

        // the head method
        HttpHead httphead = new HttpHead(url);

        HttpResponse response = httpclient.execute(httphead);

0 个答案:

没有答案