Closed olbb closed 7 years ago
Same issue here,please suggest a fix
I've been having the same issue. By looking at ANRs on the playstore I can see that they happened infrequently when I was using 4.0.0-beta 5. I had to update DBFlow when beta5 broke on Jitpack. Ever since I've shipped with beta 7 I went from having 1-5 deadlocks a day to about 25 - 50 a day.
In testing so far I haven't been able to reproduce the dead lock issue when I use .async() before calling save().
Same issue too!
Run the operations on the same thread. dont do DB ops on different threads for a start.
FlowManager.getDatabase(...).beginTransactionAsync(...).build().execute()
https://agrosner.gitbooks.io/dbflow/content/StoringData.html under Async transactions.
@agrosner Is there an advantage to using an async transaction over calling save() on an AsyncModel, or would they both do the same thing?
same thing. transaction more advantageous because you can do more within a transaction and itll overall be more efficient. Like for example:
list.forEach { it.async().save() }
Will create a transaction for each object and execute them in parallel.
FlowManager.getDatabase(MyDatabase::class.java).beginTransactionAsync { db ->
list.forEach { it.save(db) }
}.build().execute()
which will do only one transaction for any number of models.
But in some times cannot access run the operations on the same thread elegant.Like this, I got some records from the server in a background thread. At the same time I handle some user event from the UI thread, and should update the record.Although I can let them execution in a same thread, but this made code less readable. Do you have any suggestions?
if you need single model updates to happen youll have to be reactive to the changes, you can attach a model changed listener to an AsyncModel
and wait for it to return then update your UI. For readability its tough to tell depending on your architecture and also callbacks arent always that readable anyways. Thread safety though is paramount.
thanks
DBFlow Version: 4.0.3 Description: Simple way to reproduce the problem like this:
Then