数据库连接与会话相同吗?

时间:2021-09-26 13:10:45

I'm bit confused about relationship between a

我对a之间的关系感到有点困惑

  • Database Open Session
  • 数据库开放会话

  • Connection pooling

To elaborate, I'm using JDBC with Oracle 9i DB and I'm also using a Connection Pool to pool my connections.

详细说明,我正在使用JDBC和Oracle 9i DB,我也使用连接池来连接我的连接。

What I would like to know is that: When my connections are lying idle in pool, are they associated with any Open Session with database? So If I've 5 connection sitting idle in pool, does that mean there will be 5 corresponding active session Open with my database?

我想知道的是:当我的连接闲置在池中时,它们是否与任何带数据库的Open Session相关联?所以如果我在池中闲置5个连接,这是否意味着将有5个相应的活动会话打开我的数据库?

1 个解决方案

#1


4  

Ok.. I got some answer from other forums:

好的..我从其他论坛得到了一些答案:

That depends entirely on the pool implementation. It seems likely they are associated with an open session for a while, and then the sessions are closed if the connections are not used for some time, and reestablished when they're needed again.

这完全取决于池的实现。看起来它们很可能与一段时间的开放会话相关联,然后如果连接未使用一段时间会话会被关闭,并且当它们再次需要时会重新建立。

Not keeping them open for some amount of time would mean wasting the overhead of establishing connections when requests are coming in rapid-fire. Keeping them open forever would hog limited resources for no good reason. Both of these go against my understanding of the very point of having a connection pool in the first place.

在一段时间内不让它们保持打开意味着在请求快速发生时浪费建立连接的开销。永远保持开放将无缘无故地占用有限的资源。这两个都违背了我对首先建立连接池这一点的理解。

#1


4  

Ok.. I got some answer from other forums:

好的..我从其他论坛得到了一些答案:

That depends entirely on the pool implementation. It seems likely they are associated with an open session for a while, and then the sessions are closed if the connections are not used for some time, and reestablished when they're needed again.

这完全取决于池的实现。看起来它们很可能与一段时间的开放会话相关联,然后如果连接未使用一段时间会话会被关闭,并且当它们再次需要时会重新建立。

Not keeping them open for some amount of time would mean wasting the overhead of establishing connections when requests are coming in rapid-fire. Keeping them open forever would hog limited resources for no good reason. Both of these go against my understanding of the very point of having a connection pool in the first place.

在一段时间内不让它们保持打开意味着在请求快速发生时浪费建立连接的开销。永远保持开放将无缘无故地占用有限的资源。这两个都违背了我对首先建立连接池这一点的理解。