0

I am working on an app in which multiple threads can update the same database, I am unsure about how some cases wherein two threads are trying to update the same database. I search about how the room works and explored transactions as well, but it is of no use to me in this case, I am doing the same operation but from multiple threads. how should I keep the database consistent without corrupting the data?

Gaurav Rai
  • 370
  • 1
  • 3
  • 16

1 Answers1

1

Basically you should use Java synchronized method to safely write and read from the DB with multiple threads (no relation to Room library as far as I know). A synchronized method that multiple threads use would ensure mutual exclusive access to the db.

See more here: to to implement a SQLite Manager for thread-safe read/write access?

Guy_g23
  • 316
  • 2
  • 7