我正在使用Aws SimpleDb存储我的Android应用程序的数据。使用AWS android SDK,我得到了很晚的响应,有没有办法改进它,在浏览器中,它为我提供300毫秒的数据,它需要大约5到10秒的时间,然后虽然我发送请求仅限40行。
这就是我在做什么。
private ThreadPoolExecutor threadPool = new ThreadPoolExecutor(poolSize, maxPoolSize, keepAliveTime, TimeUnit.SECONDS, threadsQueue);
private void getArticles() {
String[] categories = {"kids", "Boys", "Girls",
"Men", "Women"};
for(final String category : categories) {
runTask(new Runnable() {
@Override
public void run() {
Log.e(TAG, "getting articles for category : " + category);
String select = "select * from shopDatabase where category = '" + category + "' AND relationType " +
"= 'none' AND articlePushTime > '2013-04-01 05:46:03.719 GMT+00:00' AND publishDateTime > '2013-04-01 05:46:03.719 GMT+00:00' " +
" AND score > '0' order by score desc limit 40";
SelectRequest selectRequest = new SelectRequest(select);
selectRequest.setConsistentRead(true);
List<Item> articles = sdbClient.select(selectRequest).getItems();
if(articles != null) {
Logger.log("ERROR", "SQLiteActivity", "articles size is : " + articles.size() + " for category : " + category, runCount);
} else {
Logger.log("ERROR", "SQLiteActivity", "articles size is : articles.size() = 0 OR NULL for category : " + category, runCount);
}
onDownload.onDownload();
}
});
}
}
public void runTask(Runnable task){ futures.add(threadPool.submit(任务)); // threadPool.execute(task); }
我试图对其进行分析,但我发现Unmarshalling需要花费大量时间,并且每次请求都会获得凭据。
记录响应时间:
04-05 11:39:30.724: E/SQLiteActivity(14448): getting articles for category : kids
04-05 11:39:49.914: E/SQLiteActivity(14448): articles size is : 40 for category : kids
04-05 11:39:30.754: E/SQLiteActivity(14448): getting articles for category : Boys
04-05 11:39:47.644: E/SQLiteActivity(14448): articles size is : 40 for category : Boys
04-05 11:39:48.964: E/SQLiteActivity(14448): getting articles for category : Girls
04-05 11:40:02.464: E/SQLiteActivity(14448): articles size is : 40 for category : Girls
04-05 11:39:49.924: E/SQLiteActivity(14448): getting articles for category : Men
04-05 11:40:02.724: E/SQLiteActivity(14448): articles size is : 40 for category : Men
04-05 11:40:02.664: E/SQLiteActivity(14448): getting articles for category : Women
04-05 11:40:10.024: E/SQLiteActivity(14448): articles size is : 40 for category : Women