简体   繁体   English

Android:发生其他一些ContentProvider操作/ sqlite写入时,AsyncTask中的ContentProvider请求被延迟

[英]Android: ContentProvider Request in AsyncTask get delayed when some other ContentProvider operations/sqlite writes are happening

I have a ContentProvider access in a AsyncTask which generally works fine while looking up some data stored in sqlite on the phone. 我在AsyncTask中具有ContentProvider访问权限,当在电话上查找存储在sqlite中的某些数据时,通常可以正常工作。

However I also have some other background services that do network checks and download and update some data. 但是,我还有其他一些后台服务,它们可以进行网络检查以及下载和更新一些数据。

It is observed that this network related background activity is affecting my ContentProvider. 可以观察到,该网络相关的后台活动正在影响我的ContentProvider。 The ContentProvider which entirely works on offline data either delays the response or just never returns for a long time. 完全处理脱机数据的ContentProvider会延迟响应,或者长时间不会返回。

Are then any locking/queuing mechanisms on the ContentProvider or the sqlite database? 那么,ContentProvider或sqlite数据库上是否有任何锁定/排队机制? The writes do not happen to the same tables as the reads. 写入不会发生在与读取相同的表上。

Are then any locking/queuing mechanisms on the ContentProvider or the sqlite database? 那么,ContentProvider或sqlite数据库上是否有任何锁定/排队机制? The writes do not happen to the same tables as the reads. 写入不会发生在与读取相同的表上。

  1. ContentProvider implementations require additional synchronization to be thread-safe, ie the developer is in charge of it ContentProvider实现需要额外的同步以确保线程安全,即由开发人员负责

  2. SQLite is synchronized, ie writes exclude reads SQLite已同步,即写入排除读取

In your case you might want to enable write-ahead-logging (WAL) , api 11+. 您可能需要启用api 11+的预写日志记录(WAL) This enables writes to happen in a separate journal in parallel: holding the lock and excluding parallel reads is not necessary anymore. 这使得写入可以并行发生在单独的日志中:不再需要保持锁定并排除并行读取。

See for instance: 例如参见:

SQLite, Content Providers, & Thread Safety SQLite,内容提供程序和线程安全

Official docs for SQLite locking SQLite锁定的官方文档

Good explanation of WAL WAL的很好解释

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

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