Hibernate开启收集缓存统计信息
来源:互联网 发布:网络流行用语2017 编辑:程序博客网 时间:2024/06/01 09:56
该功能依赖二级缓存,所以必须先配置开启了二级缓存功能!
分两种情况
情况一,项目中有hibernate.cfg.xml配置文件
<!-- 开启二级缓存,使用EhCache缓存 --> <property name="hibernate.cache.use_second_level_cache">true</property><property name="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</property><!-- 开启查询缓存 --><property name="hibernate.cache.use_query_cache">true</property><!-- 开启收集缓存统计信息的功能,可以查看实际缓存的内容、命中率等 --><property name="hibernate.generate_statistics">true</property><!-- optionally, force Hibernate to keep the cache entries in a more readable format --> <property name="hibernate.cache.use_structured_entries">true</property>
情况二,项目集成了Spring框架,没有hibernate.cfg.xml配置文件
<bean id="sessionFactory"class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">......<property name="hibernateProperties"> <props> ...... <!-- 开启二级缓存,使用EhCache缓存 --> <prop key="hibernate.cache.use_second_level_cache">true</prop> <prop key="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</prop> <!-- 开启查询缓存 --> <prop key="hibernate.cache.use_query_cache">true</prop> <!-- 开启收集缓存统计信息的功能,可以查看实际缓存的内容、命中率等 --> <prop key="hibernate.generate_statistics">true</prop> <!-- optionally, force Hibernate to keep the cache entries in a more readable format --> <prop key="hibernate.cache.use_structured_entries">true</prop> ...... </props></property><property name="mappingResources"> <list> <value>edu/po/Users.hbm.xml</value> <value>edu/po/TLog.hbm.xml</value> </list></property></bean>
统计信息使用的demo:
//Cache统计统计信息Statistics statistics= sessionFactory.getStatistics();System.out.println(statistics);System.out.println("放入"+statistics.getSecondLevelCachePutCount());System.out.println("命中"+statistics.getSecondLevelCacheHitCount());System.out.println("错过"+statistics.getSecondLevelCacheMissCount());//详细的Cache统计信息for (int i = 0; i < statistics.getEntityNames().length; i++) {String entityName = statistics.getEntityNames()[i];EntityStatistics entityStatistics = statistics.getEntityStatistics(entityName);StringBuilder cacheOperator = new StringBuilder();cacheOperator.append("CategoryName:" ).append(entityStatistics.getCategoryName()) .append(",DeleteCount:").append(entityStatistics.getDeleteCount()) .append(",FetchCount:").append(entityStatistics.getFetchCount()) .append(",InsertCount:").append(entityStatistics.getInsertCount()) .append(",LoadCount:").append(entityStatistics.getLoadCount()) .append(",OptimisticFailureCount:").append(entityStatistics.getOptimisticFailureCount()) .append(",UpdateCount:").append(entityStatistics.getUpdateCount()); System.out.println(cacheOperator.toString());}
项目demo: https://github.com/zengyh/SSHWebProject.git
阅读全文
0 0
- Hibernate开启收集缓存统计信息
- 开启oracle10g统计信息自动收集功能
- oracle11g查看自动收集统计信息是否开启
- Hibernate开启查询缓存
- oracle统计信息收集
- oracle统计信息收集
- 收集统计信息
- 收集统计信息
- 收集oracle统计信息
- 如何收集统计信息
- 收集oracle统计信息
- GATHER_STATS_JOB收集统计信息
- 收集oracle统计信息
- 定时收集统计信息
- 收集oracle统计信息
- 收集统计信息(三)
- 收集oracle统计信息
- 收集oracle统计信息
- MinGW安装
- 在CentOS安装CMake
- 项目中tomcat 下配置HTTPS
- 四大标签
- Android——Fragment中通过给每个Fragment设置开场动画进入
- Hibernate开启收集缓存统计信息
- UFLDL stackedae_exercise编程答案
- SpringBoot系列(3)---无配置文件SpringMVC
- 五、JAVA语法基础(3)
- 【技能库】--JS时间处理(251)
- Split()用法 isNaN MVC ...基础知识
- springmvc环境搭建中url-pattern /和/*的区别
- Number Sequence F(n)的计算
- Hibernate POJO为什么要实现Serializable接口