当应用程序启动时,应下载500张图片。但是在〜120请求isLandRef.getFile(file);
之后,我有这样的错误:java.util.concurrent.RejectedExecutionException: Task com.google.firebase.storage.StorageTask$8@800c85 rejected from java.util.concurrent.ThreadPoolExecutor@e340ada[Running, pool size = 3, active threads = 3, queued tasks = 128, completed tasks = 0]
在此错误之后,不再下载图像。我能够通过添加Thread.sleep (100);
来解决此错误,但是由于此,我的应用程序冻结了。如何在不使用Thread.sleep (100);
的情况下解决错误问题?
public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
if (data.getCount() != 0) {
for (int i = 0; i < data.getCount(); i++) {
data.moveToPosition(i);
loadImage(data.getString(data.getColumnIndexOrThrow(ExamContract.QuestionEntry.COLUMN_IMAGE)));
}
finish();
}
}
private void loadImage(String image) {
StorageReference isLandRef = FirebaseStorage.getInstance().getReference().child("images/" + image + ".jpg");
try {
File path = getDir("images", Context.MODE_PRIVATE);
File file = new File(path, image + ".jpg");
try {
isLandRef.getFile(file);
} catch (RejectedExecutionException r) {
r.printStackTrace();
Thread.sleep(100);
try {
isLandRef.getFile(file);
} catch (RejectedExecutionException j) {
Thread.sleep(100);
isLandRef.getFile(file);
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
看起来有最大队列大小。与其在一开始就排队所有工作,还应该只能得到您现在需要的东西,或者编写自己的队列并继续在每个工作完成时喂养他们的队列。