Task com.google.firebase.a.v rejected from java.util.concurrent.ThreadPoolExecutor

Jonny :

Friends,

I would like to know about this error. I am using Firebase in Android. The complete error is:

Fatal Exception: java.util.concurrent.RejectedExecutionException
Task com.google.firebase.a.v@61b9a00 rejected from java.util.concurrent.ThreadPoolExecutor@eacc239[Running, pool size = 2, active threads = 2, queued tasks = 128, completed tasks = 0]

The error is happening on DataChange inside a Fragment, who is reading the information to populate the RecyclerView.

I would like to know why is this happening and how I should avoid this error.

Thank you and sorry, because I know I am not explaining the issue in detail, but I really do not know why this is happening.

EDIT

This is the code where I realized that it shows the error. It all started when I tried to upload more than 5 pictures at the same time.

if (!pet.isUploaded()) {
    File image = new File(pet.getPicPath());
    final StorageReference referenceImage = storageRef.child("Adopcion" + "/" + pet.getOwner() + "/" + "Adopcion" + "/" + pet.getName() + pet.getAnimalID());

    Uri image2 = Uri.parse("");
    if (image.exists()) {
        image2 = Uri.fromFile(new File(image.toURI()));
    }

    UploadTask taskImage = referenceImage.putFile(image2);

    taskImage.addOnCompleteListener(new OnCompleteListener<UploadTask.TaskSnapshot>() {
        @Override
        public void onComplete(@NonNull Task<UploadTask.TaskSnapshot> task) {
            if (task.isSuccessful()) {
                if (task.getResult().getDownloadUrl() != null) {
                    pet.setUploaded(true);
                    pet.setPicPath(task.getResult().getDownloadUrl().toString());
                    mReference.child(String.valueOf(pet.getAnimalID())).setValue(pet).addOnCompleteListener(new OnCompleteListener<Void>() {
                        @Override
                        public void onComplete(@NonNull Task<Void> task) {
                            if (getActivity() != null) {
                                File folder = getActivity().getCacheDir();
                                File myFile = new File(folder, String.valueOf(pet.getAnimalID()) + ".jpg");
                                if (myFile.exists()) {
                                    myFile.delete();
                                }
                            }
                        }

                    });
                }
            }

        }
    });
}

EDIT FIX

The issue was happening because the image was being uploaded many times, because once the upload was successfully completed, I changed my pet status isUploaded to true. However, it takes a few seconds to Firebase to make that change, so the image was being uploaded many times.

What I did to fix this issue, is maybe not the best way to solve it, but it works until I can find a better way. I just use an Array to store the pet id, and once the upload was performed I tracked the pet id to know that the image was already uploaded, and then prevent the image from being queued again.

Before that fix, I realized that the image was being uploaded more than 10 times and even more if the image was created offline.

Jonny :

How i fixed the issue

The issue was happening because the image was being uploaded many times, because once the upload was successfully completed, I changed my pet status isUploaded to true. However, it takes a few seconds to Firebase to make that change, so the image was being uploaded many times.

What I did to fix this issue, is maybe not the best way to solve it, but it works until I can find a better way. I just use an Array to store the pet id, and once the upload was performed I tracked the pet id to know that the image was already uploaded, and then prevent the image from being queued again.

Before that fix, I realized that the image was being uploaded more than 10 times and even more if the image was created offline.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=431491&siteId=1