在 Android 上使用 Ormlite 进行多线程读取的性能

Performance of multi threaded read using Ormlite on Android

我想使用 Ormlite 在 Android 上使用 Sqlite 读取两个不同的 tables (DAO)。每个 table 有超过 10.000 行。

我知道我应该只通过 OpenHelperManager.getHelper(context, DatabaseHelper.class); 使用一个连接。没问题。

我的问题是,如果我使用两个并行线程来读取两个 table 是否会更快,或者数据库是否不适用于性能方面的并行访问?

SQLiteDatabase 内部有自己的锁以确保线程安全并防止并发访问。以前你可以调用 setLockingEnabled(false) to affect this, but it's deprecated since API 16. However, since API 11 you can call enableWriteAheadLogging(), which enables parallel execution of queries from multiple threads on the same database. You should call this as early as possible, so either in onConfigure() (API 16+) or onOpen().