Ser*_*rin 5 java connection hibernate connection-pooling connection-close
与我的数据库的Hibernate连接我的数据库没有关闭.在10秒内点击10次之后,我从MySQL Workbench获得了这个连接统计数据(在我的开发机器中.我是唯一的用户).MySQL Workbench服务器状态
我有这些
我的hibernate.cfg.xml
<property name="hibernate.bytecode.use_reflection_optimizer">false</property>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.password">officenic</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost/officenic</property>
<property name="hibernate.connection.username">officenic</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQL5InnoDBDialect</property>
<!-- configuration pool via c3p0 -->
<property name="hibernate.c3p0.acquire_increment">1</property>
<property name="hibernate.c3p0.idle_test_period">100</property> <!-- seconds -->
<property name="hibernate.c3p0.max_size">5</property>
<property name="hibernate.c3p0.max_statements">0</property>
<property name="hibernate.c3p0.min_size">1</property>
<property name="hibernate.c3p0.timeout">100</property> <!-- seconds -->
Run Code Online (Sandbox Code Playgroud)
我想在每次关闭会话时调用的代码块.
if (session == null)
return;
if (session.isOpen()) {
if (session.isDirty())
session.flush();
session.close();
System.out.println("Session closed");
}
Run Code Online (Sandbox Code Playgroud)
我错过了什么吗?
好吧,我似乎每次都在创建SessionFactory.这个链接有一个很好的类,使SessionFactory静态解决了这个问题.http://docs.jboss.org/hibernate/core/3.3/reference/en/html/tutorial.html#tutorial-firstapp-helpers
归档时间: |
|
查看次数: |
15249 次 |
最近记录: |