开发者

how to Handle ReadTimOut Exception while reading data from server?

开发者 https://www.devze.com 2023-04-13 08:11 出处:网络
I am downloading long files from Amazon S3 server. I log excpetions to my server DB if any occure. What I see is large number of exceptions is java.net.SocketTimeoutException: Read timed out

I am downloading long files from Amazon S3 server. I log excpetions to my server DB if any occure. What I see is large number of exceptions is java.net.SocketTimeoutException: Read timed out

I thought this is occur when user is in bad/poor internet coverage but I wonder if user is in bad coverage area then why that is logging on server?(As this also done via internet). Any body know reason?

The line at which this exception occurs every time is

while ((numRead = inputStream.read(mBuffer)) >= 0)

How I can handle that exception? I am thinking that when exception occur then I should again make a try about no of time e.g 5 time by calling

inputStream.read(mBuffer);

Is I am thinking correct?

Is after read time out exception occur the inputstream will be valid to use again?

Will calling inputStream.read(mBuffer); will be resume fr开发者_如何学运维om the last stream readed?

Thanks


The input stream remains valid, and the buffer contains no data after a timeout. If you're getting lots of timeouts I would start by increasing the timeout period. Double it. And it should be at least 30-60 seconds to start with, as you want all the data.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号