数据库连接池允许应用程序重用已存在于池中的数据库连接,以避免反复的建立新的数据库连接。这种技术能有效提高应用程序的伸缩性,因为有限的数据库连接能够给大量的客户提供服务。这种技术同时也提高的系统性能,避免了大量建立新连接的开销。

开发一个具有伸缩性的、高性能应用程序应该最大限度的减少建立连接所花费的时间,保持数据库连接最大限度的有效,以存取数据。当一个数据库连接关闭时,它只是由连接池收回以待重用,并未真正释放。但是,如果连接池被释放,数据库连接将会被释放掉。

开发人员应当注意不要依赖垃圾回收机制去释放数据库连接,因为当参数超出作用域时,数据库连接并没有得必要的关闭,这种数据库资源泄漏将导致建立新连接时抛出连接错误。

数据库连接池在初始化时将创建一定数量的数据库连接放到连接池中,这些数据库连接的数量是由最小数据库连接数来设定的。无论这些数据库连接是否被使用,连接池都将一直保证至少拥有这么多的连接数量。连接池的最大数据库连接数量限定了这个连接池能占有的最大连接数,当应用程序向连接池请求的连接数超过最大连接数量时,这些请求将被加入到等待队列中。

Connection pooling is used in web-based and enterprise applications and is handled by the application server. 


With/Without Enterprise Server
 The Enterprise Server provide a centralized location to pool connections to the database server. One of the larger drains on database server resources is connection maintenance. Even with .NET connection pooling, if clients are allowed to connect directly to the database, each client will open several connections and every connection requires significant resources on the database server to maintain  . 

 When the Enterprise Server is incorporated, it becomes the only "client" of the database server (the only computer that opens connections to the database). This allows the ES to pool the connections from all of the client computers and greatly reduces the needed database server resources. The database server can spend more of its resources running queries and serving data rather than maintaining client connections. 

 This functionality is the largest contributor to the increased application scalability that is gained from using the Enterprise Server. Additional Enterprise Servers can be added to handle client connections without greatly increasing the number of connections to the database.

Java创建一个JDBC连接
connection = connectionPool.getConnection();
SQL scripts to monitor database connections
REM
REM START OF SQL
REM
REM Connections by machine and instance
select s.machine, s.username, s.module, s.inst_id, count(*) how_many
from (select distinct PROGRAM, PADDR, machine, username, module, inst_id from gV$SESSION) s,
 gv$process p
where s.paddr = p.addr
and p.inst_id = s.inst_id
group by s.machine,s.username, s.module, s.inst_id



参考:


Logo

腾讯云面向开发者汇聚海量精品云计算使用和开发经验,营造开放的云计算技术生态圈。

更多推荐