What is difference between MysqlDataSource and MysqlConnectionPoolDataSource?

旧时模样 提交于 2019-12-21 20:42:06

问题


I am configuring a mysql connection in an application server (glassfish specifically, but I am curious about other application servers as well) and it appears that there are 2 extremely similar options for the resource type & driver. Namely, MysqlDataSource and MysqlConnectionPoolDataSource.

I am curious about what the difference between the two is. It appears that glassfish is maintaining a connection pool either way, so it's difficult to tell what the difference is.

Thanks for any insight that you can provide.


回答1:


MysqlDataSource is a Java Native Database Interface that returns a connection to a database defined in the connection params. MysqlConnectionPoolDataSource is a subclass of MysqlDataSource that returns a pooled connection resource. The difference is whether your connection resource is pooled or the target of the connection is pooled. This usually is determined by Hard resources and number of expected connections. If you have many users connecting at once you would want to pool as many of those users into one connection as your hard resources like memory would allow. Therefore you would limit the number of Instances of a driver running in memory and allow the driver to manage as many threads as it can manage internally.

Think of a network hub vs a network switch. A Switch is always faster but is never realized until the volume of traffic is large enough to matter. The same is true for your question in that a pooled connection will increase performance if the number of users reaches a potential enveloped by memory and CPU.



来源:https://stackoverflow.com/questions/15582052/what-is-difference-between-mysqldatasource-and-mysqlconnectionpooldatasource

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!