SQLite的连接和功放;锁定 [英] SQLite Connections & Locking

查看:150
本文介绍了SQLite的连接和功放;锁定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从2个不同的线程访问SQLite数据库,从而使用2个不同的数据库连接。这两个线程将主要完成从数据库中读取和将数据写入数据库只是偶尔。如果我觉得是凶多吉少两个线程写入到数据库的同时,我应该感到安全,我不应该在这种情况下的任何问题?

I'd like to access a SQLite database from 2 different threads, thereby using 2 different connections to the database. Both threads will mainly perform reads from the DB and will write to the DB only occasionally. If I feel the odds are against both threads writing to the DB at the same time, should I feel safe that I should not have any issues in this scenario ?

推荐答案

SQLite是线程安全的,并与新的版本,你可以线程之间共享一个连接。尽管如此,SQLite的常见问题指出:主题是邪恶的(我不认为他们的意思是这SQLite的背景下,但作为一般的语句)。

SQLite is threadsafe and, with recent versions, you can share a single connection among threads. That said, the SQLite FAQ states "Threads Are Evil" (I don't think they mean this in the context of SQLite, but as a general statement).

SQLite的已锁定机制,所以即使第二个实例试图如果两个线程都写得到它会排队,直到现有的锁完成了数据库的写锁,所以即使SQLite的应该适应你。常见问题解答表明,它通常是不可靠上使用多个连接距离的不同的工艺网络文件系统的,由于执行不力锁定在文件系统中,但我不认为该警告适用于您的使用。

SQLite has locking mechanisms so that even if a second instance tries to get a write lock on the database it will be queued until existing locks are finished, so even if both threads are writing SQLite should accommodate you. The FAQ suggests that it is generally not safe to use multiple connections from different processes on network file systems due to poorly implemented locking in the file system, but I don't think that warning applies to your usage.

这篇关于SQLite的连接和功放;锁定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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