开发者

Can I create support multiple database transactions on a single connection?

开发者 https://www.devze.com 2023-02-03 23:32 出处:网络
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 over

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 t开发者_JAVA百科o 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.

Any advice appreciated :)


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.


Absolutely no. every "transaction" must have begin, complete or rollback. Of course you can separate a single transaction to some parts on a single line of original transaction. no more no less.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号