问题描述
我已经创建了一个HyperSQL数据库。我只是想知道我是否可以在单个连接上运行多个事务。我不想为每个事务产生一个新的连接,因为与此相关的开销。
I have created a HyperSQL Database. I was just wondering whether I could run multiple transactions on a single connection. I didn't want to spawn a new connection for each transaction due to the overhead associated with this.
看一些类似的问题,建议似乎是创建一个池的数据库连接,然后阻塞等待一个可用的。这是一个可行但不可取的解决方案。
Looking at some similar questions the suggestion appeared to be to create a pool of database connections and then block waiting for one to become available. This is a workable, but not desirable solution.
背景信息(如果这与答案相关)。当一些请求进来时,我的应用程序将创建一个新的线程。这个请求将需要一个数据库事务。
Background Info (if this is relevant to the answer). My application will create a new thread when some request comes in. This request will require a database transaction. Then some not insignificant time later this transaction will be committed.
任何建议:)
推荐答案
您应该能够通过单个连接运行多个事务,他们只需要一次运行一个,所以你必须排队或堆栈,并阻止事务发生。您通常无法通过单个连接并行运行查询。
You should be able to run multiple transactions over a single connection they will just have to be run one at a time so you'll have to queue or stack them and block as the transaction happens. You generally will not be able to run queries in parallel over a single connection.
这篇关于我可以在单个连接上创建支持多个数据库事务吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!