Realm-java: java.util.concurrent.RejectedExecutionException while executing the transaction

Created on 7 Mar 2016  路  13Comments  路  Source: realm/realm-java

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)

T-Help

Most helpful comment

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.

All 13 comments

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

yes I have 96 rows and and inserting them using transaction

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.

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
        }
    });

@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.

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

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

@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?

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

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

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

@shashank090789 Any updates to share?

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

harshvishu picture harshvishu  路  3Comments

wezley98 picture wezley98  路  3Comments

AAChartModel picture AAChartModel  路  3Comments

tloshi picture tloshi  路  3Comments

gpulido picture gpulido  路  3Comments