SQLite 数据库中的并发 [英] Concurrency in SQLite database

查看:35
本文介绍了SQLite 数据库中的并发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

SQLite 数据库中如何实现并发?根据文档,可以使用 WAL(Write-Ahead Logging).但是,我不知道如何实现它.

How to achieve concurrency in SQLite database? As per documents it is possible using WAL(Write-Ahead Logging).But, I dont know how to implement it.

在我的应用程序中,我想从主线程上的 db 读取数据,同时后台线程正在同一个表中写入/插入一些数据.在同时执行读写查询时,应用程序停止响应,直到插入未完成.SQLite 中是否可以实现并发,以及如何实现?

In my app I want to read data from db on main thread and at the same time a background thread is writing/inserting some data in the same table. On executing read and write query at same time app stops responding until insertion isn't done. Is concurrency possible in SQLite, and how?

推荐答案

您需要使用 DataBase 对象的单例对象.为此,您可以使用 ContentProvider.哪个是实现并发的更好选择.

You need to use a singleton object of DataBase object. For this purpose you can use ContentProvider. Which is a better option to achieve concurrency.

这里是 ContentProvider 教程的链接http://www.vogella.com/articles/AndroidSQLite/article.html

您也可以参考文档http://developer.android.com/guide/topics/providers/content-providers.html

这篇关于SQLite 数据库中的并发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆