objectbox-java
objectbox-java copied to clipboard
Multi process support
we want to use the data in multi process, but i dont know whether this can use ?
~~You should be with one exception:~~ It is not supportted at the moment. To make it work we have to:
- reactive queries do not work across processes.
- ID assignment currently works NOT accross processes - multiple processes would overwrite each other when inserting
- we have to guard initialization so only one process boots up the DB at a time
If I understood correctly, it's still not possible to listen for changes that originated in different processes. Any idea on when will this be supported?
Multi process might be bumpy at the moment. Can you tell us about your use case?
@greenrobot not sure if it's relevant enough to pollute this issue. I have a service in a different process that's responsible to build all the data.
It's always relevant to see how features are (intended to be ) used; sometimes it's surprising.
Got it. And why did you decide to give the Service its own process?
It's mainly for better memory management. I might be over-engineering.
Sorry, I had to revise my initial comment. Multiple processes are not supported at the moment!
ok got it , thx bro
Btw, additional read-only processes might even work if they do not rely on reactive queries / data change listeners.
2.7.0
introduced read-only stores that enable multi-process support.
There is an example: https://github.com/objectbox/objectbox-examples/tree/main/android-app-multiprocess
Inter-process data observers are in preparation: #893
Thanks for working on this subject! I have multiple read and write operations in two separate processes. Currently it it is working quite well for most boxes except one. In this case I write in both processes. For the others it is either one of them writing.
For the one with the issues I have the issue with the error: "Error when updating with existing Id's..." (As a workaround I delete all items and add them again after it....). But also some unexpected loss of items when writing quit fast "couple of seconds" after each other.
Is it planned to support writing from multiple processes in the future?
Is it planned to support writing from multiple processes in the future?
According to our current plans, not in the near future. We advise to use one writer process and use IPC from other processes for writes via the writer process.
in my project, I moved the objectbox.init into service to avoid multiple initialization. and do a code to wait for it to be available:
override fun onPostCreate(savedInstanceState: Bundle?) {
super.onPostCreate(savedInstanceState)
GlobalScope.launch {
while(true) {
try {
if(ObjectBox.boxStore == null) {
Log.d(AdService.TAG, "Waiting for objectbox.")
return@launch
}
return@launch [email protected] {
renderApp(savedInstanceState)
}
} catch(e: java.lang.Exception) {
// skipped starting issue
Log.d(AdService.TAG, "Waiting for objectbox", e)
}
delay(1000)
}
}
}