关于android Sqlite在多进程情况下的安全 [英] About android Sqlite safety in multi-process case
问题描述
在我的应用程序中,存在多个进程,并且在每个进程中,我需要访问同一个 SQLite 数据库(当然,这意味着超过 2 个主题),所以我担心的不仅仅是线程安全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.
这种情况的一种解决方案是使用内容提供程序.但是从 android sdk,它警告说它的方法可能被调用多线程,因此必须是线程安全的.如果内容提供者本身不一定意味着线程安全,我怎么能假设它是进程安全的?
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?
文章 还阐明了 SQLiteDatabase 本身默认情况下是同步的,从而保证不会有两个线程同时接触它.如果在多进程情况下怎么办?两个进程可以同时修改同一张表吗?会崩溃吗?谷歌搜索后我没有得到任何答案......
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? I does not get any answer after googling....
推荐答案
多进程的行为就像多线程一样,即它们的事务不会被彼此干扰.
Multiple processes behave just like multiple threads, i.e., their transactions are safe from being interfered with by each other.
这篇关于关于android Sqlite在多进程情况下的安全的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!