Techniques to avoid DeadlineExceededException in G

2019-06-04 03:40发布

问题:

I am developing an Twitter4J web application in Google App Engine/Java.

I need to show two lists. One is Twitter friends and other is followers. With photo and screen name.

It is working fine for people who have 20-30 followers and friends. But it gave me DeadlineExceededException when I try a user who has 150+ followers and friends.

GAE throws this exception if web request take time more than 30 seconds.

So what techniques I can adopt to avoid this exception.

Should I generate two AJAX calls for each of my list. After page loads. So that every call will have its own 30 secs limit?

Or what else you think? I am gone make it.

Please help.

回答1:

Not sure if you intend to query all followers/friends at once (it would be a problem with the Twitter api rate limit for people with a very large number of followers/friends anyway). So I assume you query the Twitter api for a limited number of followers/friends, and using the Twitter paging to get more as needed to show.

My solution would be, and it also something I've implemented for Twitter, is to do the statuses/friends and statuses/followers from the browser. This is possible via JavaScript by adding a html <script> tag with the status url and the callback function in the browser. This bypasses GAE as proxy. This not only avoids the timeout problem on GAE it also reduces the number of calls/cpu-time in GAE, which means it will be cheaper if your applications scales up, above the free GAE limit.