开发者

Android, threads and databases

开发者 https://www.devze.com 2023-03-20 23:11 出处:网络
I need to write some application which will have a couple threads and these threads will be work with local database. I afraid that these threads will be compete among themselves for database. Is ther

I need to write some application which will have a couple threads and these threads will be work with local database. I afraid that these threads will be compete among themselves for database. Is there any simple solution to solve this problem? I read that I can use content provider becouse then will be only one connection 开发者_StackOverflow社区with database but maybe there is another solution? Thanks for all advice and tip.


Use one DataBase Helper class and create a single instance which can be accessed by both threads.

Make all the methods in DataBase Helper class as synchronized to avoid race conditions.

0

精彩评论

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