论 文
数据库连接池的研究与实现
论 文 作 者 姓 名 :
申请学位专业:
申 请 学 位 类 别 :
指导教师姓名(职称):
论 文 提 交 日 期 :
数据库连接池的研究与实现
摘 要
在基于 JDBC 的数据库实际应用开发中,对数据库连接的管理是一个重点也
是一个难点,频繁对数据库的连接与关闭操作、多客户对数据库的并发访问,一
定程度上决定了 WEB 系统的响应以及应用性能。使用数据库连接池方式能对数据
库的连接进行管理和维护,上层应用程序通过数据库连接池使用数据库资源能提
升系统性能,充分利用系统资源。文章通过介绍、分析数据库连接池工作的基本
原理,了解目前流行的 WEB 服务器在数据库连接池方面的使用现状后,总结了一
些数据库连接池开发程序中容易忽略的问题。并在学习掌握了实现连接池的关键
技术后给出了一个较为高效的连接池管理策略,在这种策略思想的指导下实际开
发出一个数据库连接池模块,使得上层应用通过本连接池访问数据库资源变得相
对高效和容易,从实际上论证了这种设计方案的可行性。
关键词:连接池;数据库;JDBC;并发访问
Research and implementation of the
Database Connection Pool
Abstract
In the practically application development of database based on JDBC, the
management of database connection is a key point and also a difficulty. The response
and performance of the WEB system are depended on frequently connecting, closing
and multi-user accessing in a certain extent. Using the Database Connection Pool can
provide management and maintenance for connections of the database. The upper
applications may access the database recourse via the Database Connection Pool, in
order to upgrade system performance and fully utilize the system recourse. This
article summarizes some issues which are easily ignored in the application
development of the Database Connection Pool by the way of introducing, analyzing
the basal theory of the Database Connection Pool and comprehending the using
situation of the Database Connection Pool on the popular WEB servers. Besides, I
established a comparatively highly effective policy of the Connection Pool
management after having learned and comprehended key technique of implementing
the Connectivity Pool, and actually had developed a Database Connection Pool
module under the guidance of that policy, causing the access of system resource by
the upper applications via current Connectivity Pool becoming relatively highly
effective and easy, demonstrated the feasibility of this design project in practice.
Key words: Database Connection Pool; Database; JDBC; Concurrence access
目 录
论文总页数:22 页
1 引言 ...........................................................................................................................................1
1.1 课题背景 ..................................................................................................................................1
1.2 连接池的主要作用 ..................................................................................................................1
1.3 目前流行的 WEB 服务器数据库连接池方面使用现状 .........................................................1
1.3.1 DHCP 介绍.........................................................................................................................2
1.3.2 Poolman 介绍...................................................................................................................2
1.3.3 C3P0 介绍.........................................................................................................................2
1.3.4 其他连接池(自写连接池)..........................................................................................2
2 相关理论基础 ...........................................................................................................................3
2.1 数据库概述 ..............................................................................................................................3
2.2 数据库连接池的基本原理 ......................................................................................................3
2.3 连接池中的关键技术 ..............................................................................................................4
2.3.1 连接池的分配与释放......................................................................................................4
2.3.2 连接池的维护..................................................................................................................5
3 系统总体设计思想及方案 .......................................................................................................5
3.1 连接池中的关键类设计 ..........................................................................................................6
3.2 连接池中的管理机制 ..............................................................................................................7
3.3 实现一个连接池的其他问题 ..................................................................................................8
3.3.1 事务处理..........................................................................................................................8
3.3.2 封装..................................................................................................................................9
3.3.3 并发..................................................................................................................................9
3.3.4 连接池的关闭..................................................................................................................9
4 具体的设计流程和实现 .........................................................................................................10
4.1 连接池的建立 ........................................................................................................................10
4.2 连接池的管理 ........................................................................................................................12
4.3 连接池的关闭 ........................................................................................................................14
4.4 连接池的测试 ........................................................................................................................15
5 系统测试问题总结 .................................................................................................................15
5.1 连接池的泄露问题 ................................................................................................................15
5.1.1 产生现象........................................................................................................................15
5.1.2 解决办法........................................................................................................................16
5.2 多数据库服务器问题 ............................................................................................................17
结 论 .........................................................................................................................................19
参考文献 .........................................................................................................................................20
致 谢 .........................................................................................................................................21
声 明 .........................................................................................................................................22