Android SQLite是线程安全的吗?

SQLite数据库本身不具有线程安全性 Android SQLiteDatabase提供了线程安全的保证,里面添加了同步逻辑。

我们操作数据库一般使用ContentProvider,SQLiteOpenHelper,应用中使用SQLiteDatabase db = SQLiteOpenHelper.getReadableDatabase(),这个db需要调用db.close()或者openHelper.close()方法吗?

不需要。

为什么? ?lq=1 ContentProvider随它的宿主进程创建,与该进程有相同的生命周期,所以不需要手动去关闭,,在内核清理进程资源的时候会将它一起清理,也就是这时候关闭的。

A content provider is created when its hosting process is created, and remains around for as long as the process does, so there is no need to close the database – it will get closed as part of the kernel cleaning up the process’s resources when the process is killed.

我知道有一种爱情,叫做与你白头,有一种幸福,叫做和你相伴。

Android SQLite是线程安全的吗?

相关文章:

你感兴趣的文章:

标签云: