多个SQLite数据库实例同时在不同的线程(QT)上打开 [英] Multiple SQLite database instances open at the same time on different Threads (QT)

查看:1461
本文介绍了多个SQLite数据库实例同时在不同的线程(QT)上打开的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从不同线程同时使用许多打开的连接是否有问题?

Is there any problem on using many open connections at the same time from different threads?

据我所知,默认情况下它是线程安全的,但这会损害性能而不是提高性能吗?

From what I've read it's thread safe by default, but, can this be hurting performance rather than improving it?

推荐答案

具有多个连接不是问题,唯一要记住的是SQLite不支持多个写入事务的并发.从SQlite 站点:

Having multiple connection is not a problem, the only thing to keep in mind is that SQLite does not support concurrency of multiple write transactions. From the SQlite site:

SQLite支持无限数量的同时读取器,但是它只能在任何时刻允许一个写入器.在许多情况下,这不是问题.作家排队.每个应用程序都会快速完成其数据库的工作并继续运行,并且锁定不会持续超过几十毫秒.但是有些应用程序需要更多的并发性,而这些应用程序可能需要寻求不同的解决方案.

SQLite supports an unlimited number of simultaneous readers, but it will only allow one writer at any instant in time. For many situations, this is not a problem. Writer queue up. Each application does its database work quickly and moves on, and no lock lasts for more than a few dozen milliseconds. But there are some applications that require more concurrency, and those applications may need to seek a different solution.

SQLite是一个非典型"数据库管理系统:实际上,它是一个提供SQL作为访问简单文件中数据库"和其他一些DBMS功能的语言的库.例如,它没有真正的并发控制(它使用操作系统功能来锁定db文件).

SQLite is an "untypical" database management system: in practice it is a library that offers SQL as language to access a simple "database-in-a-file", and a few other functionalities of DBMSs. For instance, it has no real concurrency control (it uses the Operating Systems functions to lock the db file).

因此,如果需要同时插入数据库,则应该使用其他内容,例如 PostgreSQL .

So, if you need concurrent insertions into a database, you should use something else, for instance PostgreSQL.

这篇关于多个SQLite数据库实例同时在不同的线程(QT)上打开的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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