[英]Database connection pooling datastructure
I would like to develop database connection pooling. 我想开发数据库连接池。
Could anyone please tell me about which data structure need to use to maintain the pool ? 有谁能告诉我需要使用哪种数据结构来维护池?
It should be implemented using Object Pool desing pattern . 它应该使用Object Pool desing模式实现 。 You can read about it in Kircher, Michael;
你可以在Kircher,Michael看到它; Prashant Jain;
Prashant Jain; (2002-07-04).
(2002年7月4日)。 "Pooling Pattern".
“汇集模式”。 EuroPLoP 2002. Retrieved on 2007-06-09.
EuroPLoP 2002.检索2007-06-09。 or in Object Pool Design Pattern .
或者在对象池设计模式中 。 Java implementation for
ObjectPool
and JDBCConnectionPool
classes can be found here . 可以在此处找到
ObjectPool
和JDBCConnectionPool
类的Java实现。
Object Pool is usually a singleton with two collections of objects (eg database connections) inside: 对象池通常是一个包含两个对象集合 (例如数据库连接)的单例 :
This collections can be implemented as Lists
or HashTables
or something else, depends on your needs. 此集合可以实现为
Lists
或HashTables
或其他内容,具体取决于您的需求。 For simple ObjectPool - LinkedList
structure will be good enough. 对于简单的ObjectPool -
LinkedList
结构就足够了。
而不是开发自己的,为什么不使用像Commons DBCP这样广泛使用和经过充分测试的库。
You generally need: 您通常需要:
On top of this, you can then build whatever logging/monitoring you require. 最重要的是,您可以构建所需的任何日志记录/监视。
There are also advocates for off-the-shelf connection pool frameworks. 还有提供现成的连接池框架的倡导者。 I know there are those who disagree, but I personally wouldn't go down this route-- a connection pool (a) really isn't difficult to write, (b) forms a key part of your system that you probably need to understand and customise.
我知道有些人不同意,但我个人不会走这条路 - 连接池(a)真的不难写,(b)构成你可能需要理解的系统的关键部分并定制。
Is an open source solution what you're looking for? 您正在寻找的开源解决方案是什么?
See this Sun Developer Tutorial: Connection Pooling : 请参阅此Sun Developer教程: 连接池 :
In releases prior to JDBC 2.0 every database session requires a new connection and login even if the previous connection and login used the same table and user account.
在JDBC 2.0之前的版本中,即使先前的连接和登录使用相同的表和用户帐户,每个数据库会话也需要新的连接和登录。 If you are using a JDBC release prior to 2.0 and want to improve performance, you can cache JDBC connections instead.
如果您使用的是2.0之前的JDBC版本并希望提高性能,则可以缓存JDBC连接。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.