开发者

How to know the number of DB connections opened from my application?

开发者 https://www.devze.com 2023-03-30 05:41 出处:网络
I am using a connection pool in my project. I want to know how many connections are opened? I have given 20 connections as开发者_Go百科 max no of connections. What will happen if it exceeds 20? Will t

I am using a connection pool in my project. I want to know how many connections are opened? I have given 20 connections as开发者_Go百科 max no of connections. What will happen if it exceeds 20? Will the pool manage this or it will through error?


Its more of a configuration related problem. But in general the pool will throw exception when the new request for a connection results in the number of connection exceeding the max connection setting.


Must depend on the particular connection pool implementation.

Conceptually it would be possible to wait, fail or victimise.

Waiting indefinitely is potentially a very bad thing, in a badly configured system with antisocial clients keeping connections for too long the number of waiters could grow very large.

Arbitrarily victimising some existing client and taking their connection is usually not reasonable (or indeed possible) for DB connections. So that's not likely to be seen.

Which leaves a failure - you'll get an exception on the lines of "No Connections Available". Some connection pools actually wait a while (for a configurable period of time) before throwing that exception - this deals better with cases of occasional peaks in demand.


To know the number of connections opened in Oracle you can write a query like this.

SELECT s.program, s.server, p.spid, s.username FROM v$session s, v$process p
WHERE s.type = 'USER'
and s.username != 'sys';

The query assumes that your connected to Oracle in a dedicated server mode also the query counts connections made other than the user sys.

Then you can use the result in your application. And the second question, "What will happen if it exceeds 20?" depends on your implementation of connection pool and I won't say more since it has been answered.

Hope this is helpful.

0

精彩评论

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