问题
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