欢迎投稿

今日深度:

Android SQLite是线程安全的吗?,androidsqlite线程

Android SQLite是线程安全的吗?,androidsqlite线程


(转载)http://blog.csdn.net/xu_fu/article/details/44672635

SQLite数据库本身不具有线程安全性 
Android SQLiteDatabase提供了线程安全的保证,里面添加了同步逻辑。 
http://developer.android.com/reference/android/database/sqlite/SQLiteDatabase.html#setLockingEnabled%28boolean%29 
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.


www.htsjk.Com true http://www.htsjk.com/SQLite/34719.html NewsArticle Android SQLite是线程安全的吗?,androidsqlite线程 (转载)http://blog.csdn.net/xu_fu/article/details/44672635 SQLite数据库本身不具有线程安全性  Android SQLiteDatabase提供了线程安全的保证,里面添加了...
相关文章
    暂无相关文章
评论暂时关闭