gpt4 book ai didi

mysql - c3p0 创建了这么多连接

转载 作者:行者123 更新时间:2023-11-29 03:42:59 26 4
gpt4 key购买 nike

我刚接到托管公司的电话,他们声称我的应用程序创建了超过 400 个到 mysql 数据库的连接,并导致他们的 dbms 崩溃!我使用 hibernate 和 c3p0 作为连接池,这是我的 hibernate 配置文件,

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>

<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">
jdbc:mysql://localhost/music?characterEncoding=UTF-8
</property>
<property name="connection.username">USER</property>
<property name="connection.password">PASS</property>
<property name="show_sql">true</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="current_session_context_class">thread</property>
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
<property name="hbm2ddl.auto">update</property>

<property name="hibernate.max_fetch_depth">3</property>

<property name="hibernate.connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</property>
<property name="hibernate.c3p0.acquire_increment">2</property>
<property name="hibernate.c3p0.idle_test_period">300</property>
<property name="hibernate.c3p0.timeout">1800</property>
<property name="hibernate.c3p0.max_size">25</property>
<property name="hibernate.c3p0.min_size" >3</property>
<property name="hibernate.c3p0.max_statement">0</property>
<property name="hibernate.c3p0.preferredTestQuery">select 1;</property>
<property name="hibernate.c3p0.testConnectionOnCheckout">true</property>
<property name="hibernate.c3p0.validate">true</property>

<mapping resource="com/roodakimusic/hibernate/resources/Article.hbm.xml"/>
<mapping resource="com/roodakimusic/hibernate/resources/News.hbm.xml"/>
<mapping resource="com/roodakimusic/hibernate/resources/Admin.hbm.xml"/>
<mapping resource="com/roodakimusic/hibernate/resources/Maestro.hbm.xml"/>
<mapping resource="com/roodakimusic/hibernate/resources/Roodaki.hbm.xml"/>
<mapping resource="com/roodakimusic/hibernate/resources/Photo.hbm.xml"/>


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

mysql和应用程序之间的任何对话都是这样的

    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
session.beginTransaction();
//session.doSomething
session.getTransaction().commit();

我怎么了? :D - 编辑 - 有人说它可能是一个 jdbc 连接器版本。

最佳答案

为了 future ! :

已解决。问题出在我的 HibernateUtil.java 中,这一行就是问题所在:

return new Configuration().configure().buildSessionFactory();

关于mysql - c3p0 创建了这么多连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10980471/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com