Sqlite 数据库实例线程安全吗 [英] Is Sqlite Database instance thread safe

查看:31
本文介绍了Sqlite 数据库实例线程安全吗的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含一些表的数据库.我想使用多个线程更新表.我将在所有线程中使用相同的 SQLiteDatabase 实例.

I have a database with some tables. I want to update the tables using multiple threads. I will use same instance of SQLiteDatabase in all threads.

请建议这种方法是否正确.Sqlite 数据库线程安全吗?两个不同的线程是否可以同时为不同的值集更新同一个表.

Please suggest if this approach is correct. Is Sqlite database threadsafe? Can two different threads update same table for different set of values at same time.

推荐答案

[错误:] 不,默认情况下它不是线程安全的.您应该使用与锁定相关的 SQLiteHelper 方法来提供线程安全.

[WRONG:] No, it is not thread-safe by default. You shoud use locking-related SQLiteHelper methods to provide thread safety.

:SQLiteDatabase 类默认提供锁定机制(请参阅评论),如果您在多线程上运行,则不必考虑更改任何内容具有线程安全性.

: SQLiteDatabase class provides a locking mechanism by default (see comments) and if you are running on multithread, you don't have to consider changing anything to have thread-safety.

在本文档中搜索'thread':http://developer.android.com/reference/android/database/sqlite/SQLiteDatabase.html

Search for 'thread' in this document: http://developer.android.com/reference/android/database/sqlite/SQLiteDatabase.html

阅读更多内容:

这篇关于Sqlite 数据库实例线程安全吗的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆