Google App Engine超时?

Fra*_*ank 5 google-app-engine timeout

在Google App Engine应用中,我使用以下行来从网站读取页面:

  String Url="http://...",line,Result="";

  URL url=new URL(Url+"?r="+System.currentTimeMillis());
  BufferedReader reader=new BufferedReader(new InputStreamReader(url.openStream()));

  while ((line=reader.readLine())!=null) { Result+=line+"\n"; }
  reader.close();
Run Code Online (Sandbox Code Playgroud)

但是我收到以下错误:

Uncaught exception from servlet
com.google.apphosting.api.DeadlineExceededException: This request (f5e2889605d27d42) started at 2011/09/07 03:20:41.458 UTC and was still executing at 2011/09/07 03:21:30.888 UTC.
    at sun.misc.Unsafe.park(Native Method)
    at java.util.concurrent.locks.LockSupport.parkNanos(LockSupport.java:226)
    at java.util.concurrent.locks.AbstractQueuedSynchronizer.doAcquireSharedNanos(AbstractQueuedSynchronizer.java:1037)
    at java.util.concurrent.locks.AbstractQueuedSynchronizer.tryAcquireSharedNanos(AbstractQueuedSynchronizer.java:1326)
    at com.google.common.util.concurrent.AbstractFuture$Sync.get(AbstractFuture.java:276)
    at com.google.common.util.concurrent.AbstractFuture.get(AbstractFuture.java:82)
    at com.google.appengine.tools.development.TimedFuture.get(TimedFuture.java:55)
    at com.google.common.util.concurrent.ForwardingFuture.get(ForwardingFuture.java:69)
    at com.google.apphosting.runtime.ApiProxyImpl.doSyncCall(ApiProxyImpl.java:177)
    at com.google.apphosting.runtime.ApiProxyImpl.access$000(ApiProxyImpl.java:56)
    at com.google.apphosting.runtime.ApiProxyImpl$1.run(ApiProxyImpl.java:150)
    at com.google.apphosting.runtime.ApiProxyImpl$1.run(ApiProxyImpl.java:148)
    at java.security.AccessController.doPrivileged(Native Method)
Run Code Online (Sandbox Code Playgroud)

似乎花费的时间比想要等待的时间长,如果网站速度慢,该怎么办?

Ste*_*nne 5

一个DeadlineExceededException当你的代码,处理请求到Web应用程序接管30秒的过程中被抛出。大概你的代码需要一段时间来处理,因为它必须等待从其他站点接收数据的时间长度。

您可以在任务队列上创建一个任务来获取和处理该数据,并更改您的 Web 请求/响应流以回复您的任务进度。

  • 我想指出,默认超时现在是 60 秒:https://developers.google.com/appengine/docs/whatisgoogleappengine#quotas_and_limits (2认同)