简体   繁体   English

读取时数据库已锁定[Android] [SQLite]

[英]Database locked when reading[Android][SQLite]

I'm trying to solve a db locked problem . 我正在尝试解决数据库锁定问题。 My application downloads data and write them to database at start up . 我的应用程序下载数据并在启动时将其写入数据库。 I made a thread do the writing in a transaction . 我让一个线程在事务中进行写操作。 But , when the data's amount is huge , the writing will not complete so quickly and during the that , reading data of the same table will cause a db locked error . 但是,当数据量巨大时,写入将不会很快完成,在此期间,读取同一表的数据将导致db lock错误。 Anybody has idea to solve this ? 有人有想法解决这个问题吗?

DB Locked error can be avoid by using synchronized methods 通过使用同步方法可以避免数据库锁定错误

I prefer you to use ContentProvider here. 我希望您在这里使用ContentProvider

Even though its mainly aimed to share among applications, It can be used inside our single app. 即使其主要目的是在应用程序之间共享,它也可以在我们的单个应用程序内使用。

If we use content provider, there is no worries of closing and locking of db. 如果使用内容提供程序,则无需担心数据库的关闭和锁定。

Refer Simple Content Provider for db operations 有关数据库操作,请参阅简单内容提供程序

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM