Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

java.util.concurrent.RejectedExecutionException while executing the transaction #2394

Closed
strmchsr opened this issue Mar 7, 2016 · 13 comments
Labels

Comments

@strmchsr
Copy link

strmchsr commented Mar 7, 2016

java.util.concurrent.RejectedExecutionException: Task java.util.concurrent.FutureTask@3d35e112 rejected from io.realm.internal.async.RealmThreadPoolExecutor@207080e3[Running, pool size = 5, active threads = 5, queued tasks = 100, completed tasks = 3637]
at java.util.concurrent.ThreadPoolExecutor$AbortPolicy.rejectedExecution(ThreadPoolExecutor.java:2011)
at java.util.concurrent.ThreadPoolExecutor.reject(ThreadPoolExecutor.java:793)
at java.util.concurrent.ThreadPoolExecutor.execute(ThreadPoolExecutor.java:1339)
at java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:81)
at io.realm.internal.async.RealmThreadPoolExecutor.submit(RealmThreadPoolExecutor.java:63)
at io.realm.Realm.executeTransaction(Realm.java:1091)

@cmelchior
Copy link
Contributor

Hi @shashank090789 You are getting that exception because for some reason there is 100 queued transactions? Are you somehow creating transactions in a loop?

@strmchsr
Copy link
Author

strmchsr commented Mar 7, 2016

yes I have 96 rows and and inserting them using transaction

@cmelchior
Copy link
Contributor

Instead of doing:

      for (int i = 0; i < size(); i++) {
         realm.executeTransaction(..., null);
      }

You should do

  realm.executeTransaction(new Realm.Transaction() {
    @Override
    public void execute(Realm realm) {
      for (int i = 0; i < size(); i++) {
         // insert data
      }
    }
  }), null);

The later is also more efficient.

@strmchsr
Copy link
Author

strmchsr commented Mar 7, 2016

I am using the same, but I am getting each row one by one from API so for each row following code is running

    realm.executeTransaction(new Realm.Transaction() {
        @Override
        public void execute(Realm bgRealm) {
          /// inserting data
        }
    }, new Realm.Transaction.Callback() {
        @Override
        public void onSuccess() {

            }
        }

        @Override
        public void onError(Exception e) {
            // transaction is automatically rolled-back, do any cleanup here
        }
    });

@beeender
Copy link
Contributor

beeender commented Mar 8, 2016

@shashank090789 Did you get the data for each row from the API in a background thread? In that case you don't have to use asyc transaction to make it more complex, just use the sync transaction write them one by one.

@bmunkholm bmunkholm changed the title java.util.concurrent.RejectedExecutionException while executing the transaction java.util.concurrent.RejectedExecutionException while executing the transaction Mar 8, 2016
@cmelchior
Copy link
Contributor

Hi @shashank090789
Did you mange to solve it using the above?

@strmchsr
Copy link
Author

Hi @cmelchior
no
I am getting data one one by from BLE device which is not is background thread (in broadcast receiver)

@beeender
Copy link
Contributor

@shashank090789 In that case, i suggest you to cache the 96 rows and write them in on async transaction. Or maybe there are some difficulties for this approach like the there is no end point of the broadcast?

@beeender
Copy link
Contributor

@shashank090789 Did you manage to solve this issue? Can we close it?

@strmchsr
Copy link
Author

I will check it and let you know if further get the same issue

@emanuelez
Copy link
Contributor

Thank you. We will wait a bit for your answer before closing this issue.

@kneth
Copy link
Member

kneth commented Apr 6, 2016

@shashank090789 Any updates to share?

@strmchsr
Copy link
Author

strmchsr commented Apr 7, 2016

@kneth
It's done, thanks for following up.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

5 participants