Skip to content

Instantly share code, notes, and snippets.

@kneth
Created January 20, 2015 13:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kneth/7cbad830461e57ffbe0d to your computer and use it in GitHub Desktop.
Save kneth/7cbad830461e57ffbe0d to your computer and use it in GitHub Desktop.
Scheduled queries
private void runSingleThread(ScheduledExecutorService scheduler, final AllTypes allTypes) {
testRealm.beginTransaction();
allTypes.setColumnLong(1);
testRealm.commitTransaction();
Log.d("REALM", "runSingleThread");
scheduler.schedule(new Runnable() {
@Override
public void run() {
Log.d("REALM", "run");
Realm realm = Realm.getInstance(getContext());
RealmResults<AllTypes> allTypeses = realm.where(AllTypes.class).equalTo(FIELD_LONG, 1).findAll();
Log.d("REALM", "size " + allTypeses.size());
realm.close();
}
}, 5, TimeUnit.SECONDS);
}
public void testSingleThread() {
ScheduledExecutorService scheduler;
scheduler = newSingleThreadScheduledExecutor();
testRealm.beginTransaction();
testRealm.clear(AllTypes.class);
testRealm.commitTransaction();
testRealm.beginTransaction();
AllTypes allTypes1 = testRealm.createObject(AllTypes.class);
AllTypes allTypes2 = testRealm.createObject(AllTypes.class);
AllTypes allTypes3 = testRealm.createObject(AllTypes.class);
testRealm.commitTransaction();
runSingleThread(scheduler, allTypes1);
try {
Thread.sleep(10000);
} catch (InterruptedException e) {
fail();
}
runSingleThread(scheduler, allTypes2);
runSingleThread(scheduler, allTypes3);
try {
Thread.sleep(10000);
} catch (InterruptedException e) {
fail();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment