Realm Java 0.83.0 in-memory realm multi-thread

79 views
Skip to first unread message

Kcrik K

unread,
Oct 8, 2015, 2:34:38 PM10/8/15
to Realm Java
Hello guys,

I use Realm in my android app.

I use only Realm stored in-memory, no physical database on disk.

I would like to know if I can use such a realm in different threads ? I have tried and I get the error that the realm was created on a different thread, and when I try to create a new instance of a realm with the same RealmConfiguration, it stays stuck in native code.

So my assumption is that you can't use a in-memory Realm within different threads..am I correct or is there a way to achieve that ?

Thank you

Mulong Chen

unread,
Oct 8, 2015, 11:42:04 PM10/8/15
to Kcrik K, realm...@googlegroups.com
Hell Kcrik!

Yes, you can use in-mem Realm across threads!
Like normal Realm, the same Realm instance cannot be used in different thread.
But, you can always create a Realm instance in another thread by using the same RealmConfiguration (same name, same inMemory property). They will point to the same in-mem Realm then.

Just remember, to remove the in-mem Realm from the memory, you have to close all the instances of it in every thread.
I believe you have already checked this doc :) https://realm.io/docs/java/latest/#in-memory-realm

Let us know if you have further questions!

--
Mulong Chen



--
You received this message because you are subscribed to the Google Groups "Realm Java" group.
To unsubscribe from this group and stop receiving emails from it, send an email to realm-java+...@googlegroups.com.
To post to this group, send email to realm...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/realm-java/bf4866f9-add8-4bf6-8277-8d09a33211d2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



{#HS:128919958-2008#}

Kcrik K

unread,
Oct 9, 2015, 7:13:11 AM10/9/15
to Mulong Chen, realm...@googlegroups.com
Hi Mulong (or should I say Chen ? )

I tried what you said, but as I thought, the data is gone if I close an in-memory realm and open it again.

So how can I work around that issue. I thought the data would be lost and indeed they are, which makes sense, since nothing holds onto the data any more.

Thanks,

Chris

Kcrik K

unread,
Oct 9, 2015, 8:49:29 AM10/9/15
to Mulong Chen, realm...@googlegroups.com
Ignore me guys,

my mistake was trying to use exactly the same RealmConfiguration object to instantiate another Realm in-memory, instead of creating a new RealmConfiguration from the same parameters.

Works fine now.

Thanks,

Chris
Reply all
Reply to author
Forward
0 new messages