I am doing some investigation of Realm streaming and ran into a problem.
In this simple example, I have 2 Thread objects, one for writing and one for reading. The Thread reader always gets the number of written objects as 0, but inside the recording area, the size() for the elements in the database is correct. When I restart the application, the reader gets the first ok counter before any inserts.
Thread writer = new Thread() { @Override public void run() { while (mRunning) { try { Realm r = Realm.getInstance(context, "test_db"); r.beginTransaction(); TestData data = r.createObject(TestData.class); r.commitTransaction(); Logger.e("WRITER THREAD COUNT: " + r.where(TestData.class).findAll().size()); sleep(LATENCY); } catch (InterruptedException e) { e.printStackTrace(); } } } }; writer.setPriority(Thread.MAX_PRIORITY); writer.start(); Thread reader = new Thread() { @Override public void run() { while (mRunning) { try { Logger.e("READING THREAD COUNT: " + Realm.getInstance(context, "test_db").where(TestData.class).findAll().size()); sleep(LATENCY); } catch (InterruptedException e) { e.printStackTrace(); } } } }; reader.setPriority(Thread.MAX_PRIORITY); reader.start();
Is there anything that needs to be done for this?
Thanks.
source share