Android SQLite是线程安全的吗?

##本文转载自

SQLite数据库本身不具有线程安全性
Android SQLiteDatabase提供了线程安全的保证,里面添加了同步逻辑。
http://developer.android.com/reference/android/database/sqlite/SQLiteDatabase.html#setLockingEnabled(boolean)
http://stackoverflow.com/questions/6675240/is-sqlite-database-instance-thread-safe

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

不需要。

为什么?
http://stackoverflow.com/questions/4547461/closing-the-database-in-a-contentprovider?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.

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值