与MySQL的Hibernate连接未关闭。在大约10秒钟内单击10次后,我从MySQL Workbench(在我的开发机中。我是唯一的用户)获得此连接统计信息。MySQL Workbench Server状态
我已经准备好了
我的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 -->
每当我想关闭会话时,我都会调用该代码块。
if (session == null) return; if (session.isOpen()) { if (session.isDirty()) session.flush(); session.close(); System.out.println("Session closed"); }
我想念什么吗?
好吧,似乎我每次都在创建SessionFactory。链接上有一个不错的类,使SessionFactory静态解决了该问题。http://docs.jboss.org/hibernate/core/3.3/reference/en/html/tutorial.html#tutorial- firstapp- helpers