How to create a Thread-safe ContentProvider?

自闭症网瘾萝莉.ら 提交于 2019-12-18 11:18:27

问题


Android documentation says

ContentProvider methods can be called from various ContentResolver objects in different processes and threads, they must be implemented in a thread-safe manner

And I found this post on Stackoverflow Android - sqlite content providers and multithreading which says it's thread safe already ??

So, Just wondering how to create a thread-safe ContentProvider ? Is it enough if I make the insert/update/delete methods syncronized

public synchronized Uri insert (Uri uri, ContentValues values) {

}

回答1:


You could make every method synchronized, but make sure it is absolutely necessary before you do. In cases where the underlying data source is already thread-safe making the methods synchronized could be costly. See my blog post on this topic for more information.



来源:https://stackoverflow.com/questions/7481978/how-to-create-a-thread-safe-contentprovider

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!