我有一个简单的Jersey REST Web服务,它将读取rss mix url并向网站显示最新消息。
但我面临的问题是,有时候响应非常缓慢,我多次超时(Ajax调用)
缓存有帮助吗?
@Path("/latestnews")
public class RssReader {
@GET
@Produces("text/plain")
public String hello() {
JSONArray latestnews = new JSONArray();
try {
String url = "http://www.rssmix.com/u/8159030/rss.xml";
URL feedUrl = new URL(url);
SyndFeedInput input = new SyndFeedInput();
SyndFeed feed = input.build(new XmlReader(feedUrl));
for (SyndEntry entry : (List<SyndEntry>) feed.getEntries()) {
JSONObject jsonobj_latestnews = new JSONObject();
String title = entry.getTitle();
String link = entry.getLink();
String pub_date = entry.getPublishedDate().toString();
jsonobj_latestnews.put("title", title).put("link", link).put("pub_date", pub_date);
latestnews.put(jsonobj_latestnews);
}
} catch (Exception e) {
e.printStackTrace();
}
return "jsonCallback(" + latestnews.toString() + ")";
}
}
请您告诉我如何改善上述ajax调用的响应时间?
提前致谢