Java spring mvc应用程序中的Hibernate连接计数
我有一个使用hibernate的SpringMVC(4.2.5.RELEASE)应用程序(4.3.11.Final) 现在,我们面临的问题是,数据库端的连接计数频繁地变满 在获取hibernate会话时,我试图打印连接统计数据,如Java spring mvc应用程序中的Hibernate连接计数,java,spring,hibernate,Java,Spring,Hibernate,我有一个使用hibernate的SpringMVC(4.2.5.RELEASE)应用程序(4.3.11.Final) 现在,我们面临的问题是,数据库端的连接计数频繁地变满 在获取hibernate会话时,我试图打印连接统计数据,如 Session session = sessionFactory.getCurrentSession(); Statistics stat = sessionFactory.getStatistics(); stat.setStatis
Session session = sessionFactory.getCurrentSession();
Statistics stat = sessionFactory.getStatistics();
stat.setStatisticsEnabled(true);
System.out.println("connection open count"+ stat.getCollectionFetchCount() +"Session open count"+ stat.getSessionOpenCount()+"Session Close count"+ stat.getSessionCloseCount()+"stat.getQueryCacheMissCount(): "+stat.getQueryCacheMissCount());
//logger.debug("hibernate session parameters connection count=>"+stat.getConnectCount()+"session open count==>"+stat.getSessionOpenCount());
在执行过程中,我得到了以下日志
hibernate session parameters connection count=>139591 session open count==>139590
现在,我从团队成员那里得到结论,上面的日志表示Hibernate请求连接的次数,而不是数据库发生的连接数
所以,我不知道如何解决这个问题
另外,我在hibernate配置中启用了二级缓存
properties.put("hibernate.cache.use_second_level_cache", "true");
properties.put("hibernate.cache.use_query_cache", "true");
properties.put("hibernate.cache.region.factory_class", "org.hibernate.cache.ehcache.EhCacheRegionFactory" );