Zeal Blog - 泽欧里
梦想 就像鸡蛋
要么孵化 要么臭掉
WWW Zeal Blog

MysqlConnectionPoolDataSource

zeal 2006-06-28 21:44 于 JAVA/C++ , 1852 字 |  + 0 - 0   English
Made In Zeal 转载请保留原始链接:http://www.zeali.net/entry/397
标签 ( Tags ):  ,  ,  , 

  oracle.jdbc.pool.OracleConnectionPoolDataSource , com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource 这两个来自各自的 jdbc 驱动里面的类看上去是如此相似,但事实上实现的却是两样事情。

  OracleConnectionPoolDataSource 确实是一个 Connection Pool 实现,算得上是最轻量级的 Oracle 数据库连接池实现方式;而 MysqlConnectionPoolDataSource 实际上只是一个提供给 ConnectionPool 使用的 DataSource 而已,并没有任何的连接池功能。

  所以如果你熟悉 OracleConnectionPoolDataSource 的话,可能会被 mysql Connector/J 驱动引擎里面的这个 MysqlConnectionPoolDataSource 类的名字给欺骗而把它当作连接池来使用。带来的结果就是无穷的 connection leak 。但这一点似乎 MySQL 在官方的 Manual 里面并没有很清晰的说明,以至于有人只好通过分析它的源代码来推测其实际的意义。倒是在MySQL Forum 里面 Mark Matthews 做了有一段很明确的解释

  1. Unless you're an application server vendor (or you are installing Connector/J into an application server that wants to use ConnectionPoolDataSources such as IBM Websphere), you shouldn't be using MysqlConnectionPoolDataSource
  2. In any case, the physical connection does not go away until you call PooledConnection.close(), calling conn.close() only closes the 'logical' connection, which requires that any listeners on the ConnectionPoolDataSource be called so that it can _reclaim_ but not close the physical connection so that it can be handed out again, and
  3. You're using very old versions of both Connector/J and MySQL and might want to consider upgrading (Connector/J is at 3.0.16 and the last release of MySQL 4.0 is at 4.0.24 currently, although the 'current' stable release is 4.1.10).

    ConnectionPoolDataSources are _not_ connection pools! They are 'vendors' of connections to connection pooling code. If you don't have your own connection pooling code, then you definitely don't want to be going this route!

  所以目前来说 mysql Connector/J 里面并没有一个能像使用 OracleConnectionPoolDataSource 那样在 java 程序里面简便的实现 MySQL 数据库 connection pooling 的实现。你必须自己实现或者使用第三方的连接池实现,比如 c3p0 和  proxool

This Entry was Last Modified on 2007-05-28 12:45
引用本文(TrackBack): 此功能无限期关闭ing ... 如有引用请在文中标明出处并提供超链接  
没有评论.
对于这篇日志您有什么想法?我想听听您的高见。
如果您不是没有思想的机器Spammer,请告诉我 4 + 8 =
然后任选以下两种方式之一告诉我您的身份:
1. 使用您的 OpenID
2. 使用传统留言格式
(必填) 名字
如何称呼您?
(选填) URL
在此填写您的 Blog / Homepage 的地址,我将非常乐于访问
(选填) Email
Email地址将在经过防SPAM处理后显示在页面。如果您不希望公开自己的Email,请略过此栏
并写下您的见解:
(由于需要进行SPAM过滤,如果评论提交速度慢请耐心等待)
记住我?

  如何进行评论                   当有新回复时给我发送邮件通知
除了 <b> 和 <i> 之外,其他的HTML标签都将从您的评论中去除. URL 或 Email 地址会被自动加上链接.
当您点击发表或者预览之后,系统会自动保存您此次评论的内容,以便当网络原因发表失败时直接按Ctrl-V重新粘贴上次评论内容。
注意:快捷键及自动拷贝功能仅对IE浏览器有效。
发贴统计

Tot 610/1314

日志存档
2008年
2007年
2006年
本 Blog 原创内容
遵循以下授权:

Creative Commons
(创作共用) CC

署名-非商业性
-相同方式分享
Zeal Blog 基于
Powered byPivot - 1.24.1: 'Arcee'
Pivot1.24.1
开发
Launched @
2005-04-27
 里,居也。——《说文》    里,邑也。——《尔雅》。李注:“居之邑也。”沪ICP备05024379号 Back To Home All Links Loading