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

查看:544
本文介绍了为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.

推荐答案

[错了:]没有,它不是线程安全的默认。您768,16使用锁相关的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.

搜索该文档中的线:<一href="http://developer.android.com/reference/android/database/sqlite/SQLiteDatabase.html">http://developer.android.com/reference/android/database/sqlite/SQLiteDatabase.html

和了解更多关于:

  • <一个href="http://www.touchtech.co/blog/android-sqlite-locking/">http://www.touchtech.co/blog/android-sqlite-locking/
  • Android的线程和数据库锁定
  • <一个href="http://stackoverflow.com/questions/3233477/android-sqlite-shared$p$pferences-2-threads-simultaneous-read-write">Android - ?SQLite的+共享preferences,2线程同时进行读/写
  • <一个href="https://groups.google.com/forum/#!topic/android-developers/s3blUf7CRhU">https://groups.google.com/forum/#!topic/android-developers/s3blUf7CRhU
  • http://www.touchtech.co/blog/android-sqlite-locking/
  • Android threading and database locking
  • Android -- SQLite + SharedPreferences, 2 Threads Simultaneous Read/Write?
  • https://groups.google.com/forum/#!topic/android-developers/s3blUf7CRhU

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

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