Reputation: 11
When the application starts, 500 pictures should be downloaded.
But after ~120 requests isLandRef.getFile(file);
i have got a error like this: 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]
And after this error images are no longer downloaded.
I was able to solve this error by adding Thread.sleep (100);
, but because of this my application freezes up.
How to solve the error problem without using 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();
}
}
Upvotes: 1
Views: 873
Reputation: 93559
It looks like there's a maximum queue size. Instead of queueing all your jobs at the beginning, you should either only get what you need now, or write your own queue and continue to feed their queue as each job finishes.
Upvotes: 2