简体   繁体   English

“获取时超时”URLFetch GAE / J.

[英]“Timeout while fetching” URLFetch GAE/J

I'm using the XMLReader to simply read a feed like below. 我正在使用XMLReader来简单地读取如下所示的Feed。

URLConnection urlConnection = url.openConnection(); 
XmlReader reader = new XmlReader(urlConnection); 

When this is called I receive within 5 seconds an IOException "Timeout while fetching". 当调用它时,我会在5秒内收到IOException“提取时超时”。 So I tried to set the timeouts to the max. 所以我试着将超时设置为最大值。 (10 sec) but still no luck and still an IOExeption in 5 sec. (10秒)但仍然没有运气,并且在5秒内仍然是IOExeption。

urlConnection.setConnectTimeout(10000); 

(the max is stated in documentation: http://code.google.com/intl/nl-NL/appengine/docs/java/urlfetch/overview.html ) (最大值在文档中说明: http//code.google.com/intl/nl-NL/appengine/docs/java/urlfetch/overview.html

Seems that the size of the feed is too large. 似乎饲料的尺寸太大。 When I call a smaller feed it works properly. 当我拨打较小的Feed时,它可以正常工作。 Is there any workaround or solution for this? 有没有解决方法或解决方案? I need to be able to call larger feeds. 我需要能够调用更大的Feed。

You should use setReadTimeout method that sets the read deadline: 您应该使用setReadTimeout方法设置读取截止日期:

urlConnection.setReadTimeout(10000); //10 Sec

You should be able to download larger feeds in 10 seconds. 您应该能够在10秒内下载更大的Feed。
If you still have problem, try to fiddle with this different approach. 如果你仍然有问题,试着摆弄这种不同的方法。

The reason is: 原因是:

If no data is available for the read timeout period, exception can be thrown. 如果没有可用于读取超时时间的数据,则可以抛出异常。 From the doc of Oracle 来自Oracle的文档

A SocketTimeoutException can be thrown when reading from the returned input stream if the read timeout expires before data is available for read. 如果读取超时在数据可用于读取之前到期,则在从返回的输入流读取时可以抛出SocketTimeoutException。

By the way, ReadTimeout is different with ConnectTimeout , the read timeout is the timeout to get data from the host, see different connection timeout and read timeout 顺便说一句, ReadTimeoutConnectTimeout不同,读取超时是从主机获取数据的超时,请参阅不同的连接超时和读取超时

So as @systempuntoout answer, need to set read timeout. 所以@systempuntoout回答,需要设置读取超时。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM