Android Sqlite数据库压力测试

2017/08/08 Android

query数据库5000次,Cursor不关闭不释放,导致android.database.sqlite.SQLiteException: unable to open database file (code 14)错误,大概在1000次时出现这个错误

open文件5000次导致 java.io.FileNotFoundException: open failed: EMFILE (Too many open files) 大概在1000次时出现这个错误

CursorWindow是一个缓冲区:

  • A buffer containing multiple cursor rows.

  • A {@link CursorWindow} is read-write when initially created and used locally.

  • When sent to a remote process (by writing it to a {@link Parcel}), the remote process

  • receives a read-only view of the cursor window. Typically the cursor window

  • will be allocated by the producer, filled with data, and then sent to the

  • consumer for reading.

一个CursorWindow的大小是2MB,可以通过com.android.internal.R.integer.config_cursorWindowSize配置

每个Cursor对应一个CursorWindow

CursorWindow使用的是共享内存作为数据存储区,存储结构是

如何叙述:从context.getContentResolver.query开始,到cursor.getString(0)结束

简单的版本是从SqliteDatabase.query开始到cursor.getString(0结束),这个过程中CursorWindow扮演了什么角色

CursorWindow会移动,所以有一个StartPosition,通过控制StartPosition,可以在一个大数据上移来移去,

CursorWindow填充流程:

从StartPosition开始填充,一直到将CursorWindow填充满,或者填充了数据库的所有行。

如果CursorWindow不能装下填充的第一行,那么不会报任何错误,知道Cursor.getXXX才会报初始化错误

img

Search

    Post Directory