[英]Reuse connection in database connection pool
As per my understanding, database connection pool usually works this way: 据我了解,数据库连接池通常以这种方式工作:
My question is : 我的问题是 :
Can we execute multiple db operations through one connection after we acquire it from the pool instead of do one db operation then put it back? 从池中获取连接后,是否可以通过一个连接执行多个数据库操作,而不是先执行一个数据库操作然后放回数据库? it's seems more efficient, because it saves the time acquiring and putting back the connection.
它似乎更有效,因为它节省了获取和恢复连接的时间。 (under multiple threads condition, there must be some cost of locking when
add
and get
from the connection pool) (在多线程情况下,从连接池进行
add
和get
时必须有一定的锁定成本)
can anyone help? 有人可以帮忙吗? Thks!
ks!
Yes, the database connection can be used for multiple operations each time it is acquired from the pool, and this behavior is typical for database applications that use pooling. 是的,每次从池中获取数据库连接时,该数据库连接都可以用于多种操作,并且这种行为对于使用池的数据库应用程序是很典型的。 For example, a connection might be acquired once and reused for several operations during the handling of a request to a REST service.
例如,在处理对REST服务的请求期间,连接可能只获得一次,并可以重复用于若干操作。 This lifecycle also often involves managing those operations as a single transaction in the database.
此生命周期通常还涉及将这些操作作为数据库中的单个事务进行管理。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.