Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

About android Sqlite safety in multi-process case

Tags:

android

sqlite

In my application, there exist more than one process, and in each process, I need access the same SQLite database (of course, it means more than 2 theads), so I worried about not only the thread-safety about the SQLite, but also the process-safety.

One solution for this case is using content-provider. But from android sdk, it warns that its methods may be called from multiple threads and therefore must be thread-safe. If content provider itself not necessarily means thread-safe, how can I assume it is process-safe?

The article also clarifies that SQLiteDatabase itself is synchronized by default, thus guaranteeing that no two threads will ever touch it at the same time. What if in the multi-process case? Can two processes modify the same table at the same time? Will it crash?

like image 330
mianlaoshu Avatar asked Sep 10 '14 04:09

mianlaoshu


1 Answers

Multiple processes behave just like multiple threads, i.e., their transactions are safe from being interfered with by each other.

like image 88
CL. Avatar answered Sep 25 '22 08:09

CL.