简体   繁体   English

Hibernate c3p0和DBCP连接池机制

[英]Hibernate c3p0 and DBCP connection pooling mechanism

If you don't specify settings in hibernate.cfg.xml what will be default connection pooler and how do you change it? 如果您未在hibernate.cfg.xml中指定设置,那么什么是默认连接池,如何更改它? here is hibernate config 这是休眠配置

<hibernate-configuration>
  <session-factory>
    <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
    <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
    <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/POM_IVR</property>
    <property name="hibernate.connection.username">root</property>
    <property name="hibernate.connection.password">XXX</property>
    <property name="hibernate.show_sql">true</property>
    <property name="hibernate.current_session_context_class">thread</property>
    <property name="hibernate.query.factory_class">org.hibernate.hql.classic.ClassicQueryTranslatorFactory</property>
    <mapping resource="com/SurveyResults.hbm.xml"/>

  </session-factory>
</hibernate-configuration>

Questions 1. Does c3p0 jar come with hibernate3? 问题1. c3p0 jar是否随hibernate3一起提供?

2.If you don't specify c3p0 , does hibernate use it's default connection pooler( how do you know it is not using default, is there a parameter) or DBCP? 2.如果您未指定c3p0,则休眠是否使用它的默认连接池(您如何知道它没有使用默认值,是否有参数)或DBCP?

3.How do I modify the DCBP paramater for my web application do I have to change the context file conf/catalina/locahost/Applicationame.xml in catalina or hibernate configuration, what do I have to change/add to it do I have to specify the username and password or just parameter? 3.如何为我的Web应用程序修改DCBP参数,是否必须在catalina或休眠配置中更改上下文文件conf / catalina / locahost / Applicationame.xml,我必须更改/添加什么?指定用户名和密码还是仅参数?

4.Can someone explain how this works, hibernate request a connection and tomcat will get a connection from pool? 4.有人可以解释一下它是如何工作的,休眠请求连接,tomcat将从池中获得连接吗? if you specify c3p0 does DBCP get by-passed? 如果指定c3p0,DBCP是否被绕过?

5.What if I have 2 web application using the same table/username/password? 5.如果我有2个Web应用程序使用相同的表/用户名/密码怎么办? what is commandeered should they have their own DBCP , c3p0 jar? 他们应该有自己的DBCP c3p0 jar,这是什么命令? if conf/context.xml is applied to all application can you specify global parameter for DBCP for application to use? 如果将conf / context.xml应用于所有应用程序,可以为DBCP指定全局参数供应用程序使用吗?

This is all related to 8 hours connection timeout for mysql, I don't want to change the DB parameters. 这都与mysql的8小时连接超时有关,我不想更改数据库参数。

Yes, c3p0 is part of hibernate: http://www.informit.com/articles/article.aspx?p=353736&seqNum=4 是的,c3p0是休眠的一部分: http : //www.informit.com/articles/article.aspx ?p=353736&seqNum =4

Listing 10.2 Sample Hibernate c3p0 Configuration 清单10.2 Hibernate c3p0配置示例

hibernate.c3p0.max_size=1 hibernate.c3p0.max_size = 1
hibernate.c3p0.min_size=0 hibernate.c3p0.min_size = 0
hibernate.c3p0.timeout=5000 hibernate.c3p0.timeout = 5000
hibernate.c3p0.max_statements=100 hibernate.c3p0.max_statements = 100
hibernate.c3p0.idle_test_period=300 hibernate.c3p0.idle_test_period = 300
hibernate.c3p0.acquire_increment=2 hibernate.c3p0.acquire_increment = 2

i believe all your answers are there. 我相信您所有的答案都在那里。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM