每个线程一个SQLiteConnection? [英] One SQLiteConnection per thread?

查看:216
本文介绍了每个线程一个SQLiteConnection?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用SQLite从system.data.sqlite.org

I am using SQLite from system.data.sqlite.org

我们需要访问从多个线程数据库(因各种原因)。我读过很多关于sqlite的线程安全功能(默认同步接入方式就够了)。

We need to access the database from many threads (for various reasons). I've read a lot about sqlite thread safe capabilities (the default synchronized access mode is fine for me).

我不知道是否有可能只需打开每一个连接线。是这样的可能吗?我真的不关心竞争条件(已尚未插入要求的东西)。我只是一个事实,即它可以访问使用数据有兴趣有一个 SQLiteConnection 每个线程对象。

I wonder if it is possible to simply open a connection per thread. Is something like this possible? I really don't care about race conditions (request something that hasn't been inserted yet). I am only interested in the fact that it is possible to access the data using one SQLiteConnection object per thread.

推荐答案

是的。事实上,这是正确的方式,因为SQLite是不是线程安全的(默认情况下,你可以把它线程与一些选项编译)。而刚刚以确保它的工作原理:在一些小网站正在使用SQLite的,所以多线程是存在的:)

Yes. In fact, it's the proper way, as SQLite is not thread safe (by default. You can make it threadsafe compiling with some option). And just to ensure it works: SQLite is being used in some small websites, so multithreading is there :)

下面信息的 http://www.sqlite.org/faq.html#q6

这篇关于每个线程一个SQLiteConnection?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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