Android 文档说
ContentProvider methods can be called from various ContentResolver objects in different processes and threads, they must be implemented in a thread-safe manner
我在 Stackoverflow 上找到了这篇文章 Android - sqlite content providers and multithreading 这说明它已经是线程安全的了??
所以,只是想知道如何创建线程安全的 ContentProvider
?如果我使插入/更新/删除方法 syncronized
public synchronized Uri insert (Uri uri, ContentValues values) {
}
最佳答案
您可以使每个方法同步
,但在您这样做之前确保它是绝对必要的。在底层数据源已经是线程安全的情况下,使方法 synchronized
可能代价高昂。看我的blog post有关此主题的更多信息。
关于android - 如何创建线程安全的 ContentProvider?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7481978/