Android sqlite concurrency without exceptions

后端 未结 2 1484
你的背包
你的背包 2020-12-11 02:47

Sqlite on android lets you access the database from multiple procs for reads, but if you\'re currently writing from one process, reads and writes from other procs will throw

相关标签:
2条回答
  • 2020-12-11 03:16

    So long as you're using the same SQLiteDatabase object, the synchronisation is done for you.

    So if you access the object via a singleton, there should be no problem. Though you may want to add some further logic if you want to implement a timeout, e.g. wait/notify or something similar.

    0 讨论(0)
  • 2020-12-11 03:26

    Or you can use another database that does support it, like H2. I know it may sound like a strange idea. But according to my initial test it works well (on the emulator as well as on the device), and is actually not slower. Except for opening and closing a database, which is currently quite slow, about 1 second, but that has other reasons, and hopefully will get fixed in the next version.

    0 讨论(0)
提交回复
热议问题