理解URLConnection.setReadTimeout() [英] understanding URLConnection.setReadTimeout()

查看:466
本文介绍了理解URLConnection.setReadTimeout()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请考虑以下代码段:

URLConnection connection = target.openConnection();

connection.setConnectTimeout(5000); // 5 sec
connection.setReadTimeout(10000); // 10 sec

connection.setReadTimeout 设置STARTING读取数据的最大可用时间,还是可用于完成读取数据的最大时间?

Does the connection.setReadTimeout sets the maximum time available for STARTING read data or is it the maximum time available for COMPLETING read data?

我的理解是,java有10秒钟的启动时间从连接中读取下一个数据字节。完成从连接读取所有数据没有超时,因为我们不知道可能有多大。它是否正确?

My understaning is that with that, java has 10 seconds to start reading the next byte of data from the connection. There is no timeout for finishing read all data from the connection as we do not know how big the strean may be. Is it correct?

推荐答案

根据oracle docs,如果没有可用于读取超时期限的数据,则可以抛出异常

According to oracle docs, if no data is available for the read timeout period, exception can be thrown


如果读取超时在数据可用于$ b $之前到期,则从返回的
输入流读取时可能抛出SocketTimeoutException b读。

A SocketTimeoutException can be thrown when reading from the returned input stream if the read timeout expires before data is available for read.

这篇关于理解URLConnection.setReadTimeout()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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