在实际使用情况和SQLite文档的上下文中,EnableWriteAheadLogging的线程安全性如何? [英] How thread safe is EnableWriteAheadLogging in the context of real usage and SQLite documentation?

查看:141
本文介绍了在实际使用情况和SQLite文档的上下文中,EnableWriteAheadLogging的线程安全性如何?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

android文档在此处描述了"EnableWriteAheadLogging":

The android documentation describes "EnableWriteAheadLogging" over here:

http://developer.android.com/reference/android/database/sqlite/SQLiteDatabase.html#enableWriteAheadLogging()

此方法允许从同一数据库上的多个线程并行执行查询"

"This method enables parallel execution of queries from multiple threads on the same database"

但是,根据SQLite文档: https://www.sqlite.org/threadsafe.html

However, according to the SQLite documentation: https://www.sqlite.org/threadsafe.html

SQLite有两种多线程处理:序列化"和多线程".使用"EnableWriteAheadLogging"时使用哪个?

there are two kinds of multithreading for SQLite: "Serialized" and "Mulit-thread". Which one is used when using "EnableWriteAheadLogging"?

此外,如果我的应用程序和后台服务都需要访问我的数据库,那么使用EnableWriteAheadLogging是否有帮助?我应该采取哪些措施来确保可以以线程安全的方式完成此操作?

In addition, if my database needs to be accessed by both my app and a background service, does it help to use EnableWriteAheadLogging? Which actions should I take to make sure this can be done in a thread safe way?

推荐答案

这与线程安全没有关系.

在WAL模式下,编写者不会阻止读者,因此Android框架认为在这种情况下使用较大的连接池是个好主意.

In WAL mode, a writer does not block readers, so the Android framework thinks it is a good idea to use a larger connection pool in this case.

也许不是,例如此评论显示:

private void setMaxConnectionPoolSizeLocked() {
    if ((mConfiguration.openFlags & SQLiteDatabase.ENABLE_WRITE_AHEAD_LOGGING) != 0) {
        mMaxConnectionPoolSize = SQLiteGlobal.getWALConnectionPoolSize();
    } else {
        // TODO: We don't actually need to restrict the connection pool size to 1
        // for non-WAL databases. There might be reasons to use connection pooling
        // with other journal modes. For now, enabling connection pooling and
        // using WAL are the same thing in the API.
        mMaxConnectionPoolSize = 1;
    }
}

这篇关于在实际使用情况和SQLite文档的上下文中,EnableWriteAheadLogging的线程安全性如何?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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