开发者

How to create a Thread-safe ContentProvider?

开发者 https://www.devze.com 2023-04-06 06:07 出处:网络
Android documentation says ContentProvider methods can be called from various ContentResolver objects in different processes and threads, they must be implemented

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 A开发者_如何学Cndroid - 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) {

}


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消