Source:
public RealmAsyncTask executeTransactionAsync(final Transaction transaction, final Realm.Transaction.OnSuccess onSuccess, final Realm.Transaction.OnError onError) { checkIfValid(); if (transaction == null) { throw new IllegalArgumentException("Transaction should not be null"); } final boolean canDeliverNotification = sharedRealm.capabilities.canDeliverNotification(); if ((onSuccess != null || onError != null) && !canDeliverNotification) { throw new IllegalStateException("Your Realm is opened from a thread without a event looper." + " The callback cannot be invoked."); } final RealmConfiguration realmConfiguration = getConfiguration(); final RealmNotifier realmNotifier = sharedRealm.realmNotifier; final Future<?> pendingTransaction = asyncTaskExecutor.submitTransaction(new Runnable() { @Override public void run() { if (Thread.currentThread().isInterrupted()) { return; } final SharedRealm.VersionID[] versionID = new SharedRealm.VersionID[1]; final Throwable[] exception = new Throwable[1]; final Realm bgRealm = Realm.getInstance(realmConfiguration); bgRealm.beginTransaction(); try { transaction.execute(bgRealm); if (Thread.currentThread().isInterrupted()) { return; } bgRealm.commitTransaction(); versionID[0] = bgRealm.sharedRealm.getVersionID(); } catch (final Throwable e) { exception[0] = e; } finally { bgRealm.close(); } final Throwable backgroundException = exception[0]; if (canDeliverNotification ) { if (versionID[0] != null && onSuccess != null) { realmNotifier.post(new Runnable() { @Override public void run() { if (isClosed()) { onSuccess.onSuccess(); return; } if (sharedRealm.getVersionID().compareTo(versionID[0]) < 0) { sharedRealm.realmNotifier.addTransactionCallback(new Runnable() { @Override public void run() { onSuccess.onSuccess(); } }); } else { onSuccess.onSuccess(); } } }); } else if (backgroundException != null) { realmNotifier.post(new Runnable() { @Override public void run() { if (onError != null) { onError.onError(backgroundException); } else { throw new RealmException("Async transaction failed", backgroundException); } } }); } } else { if (backgroundException != null) { throw new RealmException("Async transaction failed", backgroundException); } } } }); return new RealmAsyncTaskImpl(pendingTransaction, asyncTaskExecutor); }

Target:
public RealmAsyncTask executeTransactionAsync(final Transaction transaction, final Realm.Transaction.OnSuccess onSuccess, final Realm.Transaction.OnError onError) { checkIfValid(); if (transaction == null) { throw new IllegalArgumentException("Transaction should not be null"); } final boolean canDeliverNotification = sharedRealm.capabilities.canDeliverNotification(); if ((onSuccess != null || onError != null)) { sharedRealm.capabilities.checkCanDeliverNotification("Callback cannot be delivered on current thread."); } final RealmConfiguration realmConfiguration = getConfiguration(); final RealmNotifier realmNotifier = sharedRealm.realmNotifier; final Future<?> pendingTransaction = asyncTaskExecutor.submitTransaction(new Runnable() { @Override public void run() { if (Thread.currentThread().isInterrupted()) { return; } final SharedRealm.VersionID[] versionID = new SharedRealm.VersionID[1]; final Throwable[] exception = new Throwable[1]; final Realm bgRealm = Realm.getInstance(realmConfiguration); bgRealm.beginTransaction(); try { transaction.execute(bgRealm); if (Thread.currentThread().isInterrupted()) { return; } bgRealm.commitTransaction(); versionID[0] = bgRealm.sharedRealm.getVersionID(); } catch (final Throwable e) { exception[0] = e; } finally { bgRealm.close(); } final Throwable backgroundException = exception[0]; if (canDeliverNotification ) { if (versionID[0] != null && onSuccess != null) { realmNotifier.post(new Runnable() { @Override public void run() { if (isClosed()) { onSuccess.onSuccess(); return; } if (sharedRealm.getVersionID().compareTo(versionID[0]) < 0) { sharedRealm.realmNotifier.addTransactionCallback(new Runnable() { @Override public void run() { onSuccess.onSuccess(); } }); } else { onSuccess.onSuccess(); } } }); } else if (backgroundException != null) { realmNotifier.post(new Runnable() { @Override public void run() { if (onError != null) { onError.onError(backgroundException); } else { throw new RealmException("Async transaction failed", backgroundException); } } }); } } else { if (backgroundException != null) { throw new RealmException("Async transaction failed", backgroundException); } } } }); return new RealmAsyncTaskImpl(pendingTransaction, asyncTaskExecutor); }