如何在 java、MySQL 和 Tomcat 6 中使用连接池
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/329666/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to use connection pool with java,MySQL and Tomcat 6
提问by José Leal
How can I use Connection pool in Java+MySQL+Tomcat 6?
如何在 Java+MySQL+Tomcat 6 中使用连接池?
I've read this article http://dev.mysql.com/tech-resources/articles/connection_pooling_with_connectorj.htmlbut it is still not quite clear for me.
我已经阅读了这篇文章http://dev.mysql.com/tech-resources/articles/connection_pooling_with_connectorj.html但对我来说仍然不太清楚。
Where do I use the Connector/J? Do I put it in a static variable? Do I use a SessionListener? Does it need any configuration?
我在哪里使用连接器/J?我把它放在一个静态变量中吗?我使用 SessionListener 吗?它需要任何配置吗?
Thank you in advance!
先感谢您!
回答by carson
You should read the Tomcat 6 JNDI document. Look for the "JDBC Data Sources" section and it will tell you everything you need to know about pooling connections with Tomcat.
您应该阅读Tomcat 6 JNDI 文档。查找“JDBC 数据源”部分,它会告诉您有关使用 Tomcat 连接池的所有信息。
回答by Sagi Bron
You can easily implement MySQL connection pooling in Java by using Java's GenericObjectPool that provides robust pooling functionality for arbitrary objects.
您可以使用 Java 的 GenericObjectPool 在 Java 中轻松实现 MySQL 连接池,它为任意对象提供强大的池功能。
See detailed example in this post: How to set up a MySQL connection pool in Java
请参阅这篇文章中的详细示例:如何在 Java 中设置 MySQL 连接池