- 浏览: 1217477 次
- 性别:
- 来自: 上海
文章分类
最新评论
-
lankk:
lankk 写道事实上,在运行String s1=new St ...
理解String 及 String.intern() 在实际中的应用 -
lankk:
事实上,在运行String s1=new String(&qu ...
理解String 及 String.intern() 在实际中的应用 -
lankk:
同意1楼的说法http://docs.oracle.com/j ...
理解String 及 String.intern() 在实际中的应用 -
raoyutao:
...
jdk 线程池 ThreadPoolExecutor -
hongdanning:
理解了。之前困惑的一些明白了。谢谢分享。
理解String 及 String.intern() 在实际中的应用
配置二级缓存
hibernate.cfg.xml
<?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="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</property> <property name="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</property> <property name="hibernate.connection.driver_class">net.sourceforge.jtds.jdbc.Driver</property> <property name="hibernate.connection.url">jdbc:jtds:sqlserver://localHost:1433/DSO</property> <property name="hibernate.connection.username">sa</property> <property name="hibernate.connection.password">sa</property> <property name="show_sql">false</property> <mapping resource="ComPermission.hbm.xml" /> </session-factory> </hibernate-configuration>
ehcache.xml
<ehcache> <diskStore path="java.io.tmpdir" /> <defaultCache maxElementsInMemory="10000" eternal="false" timeToIdleSeconds="1200" timeToLiveSeconds="1200" overflowToDisk="true" /> </ehcache>
ComPermission.hbm.xml
<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <hibernate-mapping> <class name="ComPermission" table="JB_COM_PERMISSION" dynamic-insert="true" dynamic-update="true"> <cache usage="read-write" include="all" /> <id name="permissionId" type="java.lang.String"> <column name="PERMISSION_ID" length="5" /> <generator class="assigned"></generator> </id> <property name="permissionCode" type="java.lang.String"> <column name="PERMISSION_CODE" length="5" not-null="true" /> </property> <property name="permissionName" type="java.lang.String"> <column name="PERMISSION_NAME" length="30" not-null="true" /> </property> <property name="remark" type="java.lang.String"> <column name="REMARK" length="255" /> </property> </class> </hibernate-mapping>
Java实体类 ComPermission
public class ComPermission implements java.io.Serializable { // Fields private String permissionId; private String permissionCode; private String permissionName; private String remark; }
log4j设置
log4j.category.org.hibernate.cache=DEBUG,CA log4j.category.org.hibernate.SQL=DEBUG,CA
测试代码
public static void main(String[] args) { System.out.println(HibernateSessionFactory.getConfiguration()); System.out.println("|||||||||||||||||||||||||||||||||||||||||||"); Session session = HibernateSessionFactory.getSessionFactory().openSession(); long start = System.currentTimeMillis(); try { ComPermission permission = (ComPermission) session.load(ComPermission.class, "10001"); System.out.println(permission.getPermissionName()); } catch (RuntimeException re) { throw re; } finally { session.close(); } System.out.println("time :" + (System.currentTimeMillis() - start)); System.out.println("-----------------------------------------------"); Transaction tran = null; Session session2 = HibernateSessionFactory.getSessionFactory().openSession(); start = System.currentTimeMillis(); try { tran = session2.beginTransaction(); ComPermission permission = (ComPermission) session2.load(ComPermission.class, "10001"); permission.setPermissionName(permission.getPermissionName() + "!"); System.out.println(permission.getPermissionName()); session2.update(permission); tran.commit(); } catch (RuntimeException re) { tran.rollback(); throw re; } finally { session2.close(); } System.out.println("time :" + (System.currentTimeMillis() - start)); System.out.println("---------------------------------------------------------"); Session session3 = HibernateSessionFactory.getSessionFactory().openSession(); start = System.currentTimeMillis(); try { ComPermission permission = (ComPermission) session3.load(ComPermission.class, "10001"); System.out.println(permission.getPermissionName()); } catch (RuntimeException re) { throw re; } finally { session3.close(); } System.out.println("time :" + (System.currentTimeMillis() - start)); System.out.println("---------------------------------------------------------"); Session session4 = HibernateSessionFactory.getSessionFactory().openSession(); start = System.currentTimeMillis(); try { ComPermission permission = (ComPermission) session4.load(ComPermission.class, "10001"); System.out.println(permission.getPermissionName()); } catch (RuntimeException re) { throw re; } finally { session4.close(); } System.out.println("time :" + (System.currentTimeMillis() - start)); }
log信息
DEBUG [org.hibernate.cache.CacheFactory.createCache:39] instantiating cache region: ComPermission usage strategy: read-write WARN [org.hibernate.cache.EhCacheProvider.buildCache:103] Could not find configuration [ComPermission]; using defaults. DEBUG [org.hibernate.cache.EhCacheProvider.buildCache:106] started EHCache region: ComPermission org.hibernate.cfg.Configuration@c4fe76 ||||||||||||||||||||||||||||||||||||||||||| DEBUG [org.hibernate.cache.ReadWriteCache.get:75] Cache lookup: ComPermission#10001 //尝试在缓存中查找对象 ComPermission#10001 DEBUG [org.hibernate.cache.EhCache.get:104] key: ComPermission#10001 DEBUG [org.hibernate.cache.EhCache.get:113] Element for ComPermission#10001 is null DEBUG [org.hibernate.cache.ReadWriteCache.get:91] Cache miss: ComPermission#10001 //找不到 DEBUG [org.hibernate.jdbc.AbstractBatcher.log:346] select compermiss0_.PERMISSION_ID as PERMISSION1_0_0_, compermiss0_.PERMISSION_CODE as PERMISSION2_0_0_, compermiss0_.PERMISSION_NAME as PERMISSION3_0_0_, compermiss0_.REMARK as REMARK0_0_ from JB_COM_PERMISSION compermiss0_ where compermiss0_.PERMISSION_ID=? DEBUG [org.hibernate.cache.ReadWriteCache.put:148] Caching: ComPermission#10001 DEBUG [org.hibernate.cache.EhCache.get:104] key: ComPermission#10001 DEBUG [org.hibernate.cache.EhCache.get:113] Element for ComPermission#10001 is null DEBUG [org.hibernate.cache.ReadWriteCache.put:160] Cached: ComPermission#10001 //将查询到的缓存起来 测试信息 time :47 ----------------------------------------------- DEBUG [org.hibernate.cache.ReadWriteCache.get:75] Cache lookup: ComPermission#10001 DEBUG [org.hibernate.cache.EhCache.get:104] key: ComPermission#10001 DEBUG [org.hibernate.cache.ReadWriteCache.get:85] Cache hit: ComPermission#10001 //找到了 测试信息! DEBUG [org.hibernate.cache.ReadWriteCache.lock:113] Invalidating: ComPermission#10001 DEBUG [org.hibernate.cache.EhCache.get:104] key: ComPermission#10001 DEBUG [org.hibernate.jdbc.AbstractBatcher.log:346] update JB_COM_PERMISSION set PERMISSION_NAME=? where PERMISSION_ID=? DEBUG [org.hibernate.cache.ReadWriteCache.release:195] Releasing: ComPermission#10001 //由于对象被更新 将缓存中的对象释放 DEBUG [org.hibernate.cache.EhCache.get:104] key: ComPermission#10001 time :31 --------------------------------------------------------- DEBUG [org.hibernate.cache.ReadWriteCache.get:75] Cache lookup: ComPermission#10001 DEBUG [org.hibernate.cache.EhCache.get:104] key: ComPermission#10001 DEBUG [org.hibernate.cache.ReadWriteCache.get:94] Cached item was locked: ComPermission#10001 //lockable.isGettable(txTimestamp)==false DEBUG [org.hibernate.jdbc.AbstractBatcher.log:346] select compermiss0_.PERMISSION_ID as PERMISSION1_0_0_, compermiss0_.PERMISSION_CODE as PERMISSION2_0_0_, compermiss0_.PERMISSION_NAME as PERMISSION3_0_0_, compermiss0_.REMARK as REMARK0_0_ from JB_COM_PERMISSION compermiss0_ where compermiss0_.PERMISSION_ID=? DEBUG [org.hibernate.cache.ReadWriteCache.put:148] Caching: ComPermission#10001 DEBUG [org.hibernate.cache.EhCache.get:104] key: ComPermission#10001 DEBUG [org.hibernate.cache.ReadWriteCache.put:160] Cached: ComPermission#10001 //重新缓存对象 测试信息! time :0 --------------------------------------------------------- DEBUG [org.hibernate.cache.ReadWriteCache.get:75] Cache lookup: ComPermission#10001 DEBUG [org.hibernate.cache.EhCache.get:104] key: ComPermission#10001 DEBUG [org.hibernate.cache.ReadWriteCache.get:85] Cache hit: ComPermission#10001 //缓存命中 测试信息! time :0
发表评论
-
连接池exception GetConnectionTimeoutException get/close not same thread
2015-09-24 14:44 7081环境 hibernate 4.2.0.Final sp ... -
hibernate spring 整合 Annotation SessionFactory java.lang.NoSuchMethodError
2015-03-26 09:40 1174使用Annotation整合Spring2.5和Hiber ... -
hibernate 一对多 排序 set
2011-05-19 11:50 2384一个note对象下面有多个comment 显示的时候希望按c ... -
hibernate 懒加载问题的一个临时解决方案
2011-05-06 11:00 1740hibernate的懒加载问题时常会困扰着我们, 今天发现了h ... -
hql select where in
2010-10-28 19:19 865public List<User> getUser ... -
hibernate sql return scalar 返回值的顺序问题 native sql
2010-06-23 11:22 3425hibernate 里面用sql查询时 在没有return s ... -
hibernate sql 放到 hbm.xml中
2010-06-09 14:25 5717<?xml version="1.0" ... -
hibernate update 不是马上发出
2010-04-22 21:10 1007有时要手动让他立刻发出 -
fix No Hibernate Session bound to thread
2010-04-09 12:34 1077@Transactional @TransactionCon ... -
查看hibernate 实际发出的sql语句
2010-03-18 17:24 2293平常的show_sql=true 最后的参数只能看到一个? ... -
hibernate 映射文件 schema catalog 参数 导致的问题
2010-01-26 14:12 2412<hibernate-mapping> &l ... -
Xdoclet 笔记
2009-12-11 18:46 1353xdoclet2的网址: http://xdoclet. ... -
Hibernate 抓取策略
2009-12-11 18:30 1179hibernate抓取策略(单端代理的批量抓取) 保持< ... -
Hibernate 查询
2009-12-11 18:23 1263在hql中关键字不区分大小写,属性和类名区分大小写 1、简单 ... -
Hibernate 继承 及 锁
2009-12-11 18:20 1183每个类继承树映射成 ... -
Hibernate 关联映射
2009-12-11 18:19 1953------------------------------- ... -
hibernate 笔记
2009-12-11 18:14 1163第一个hibernate项目 1、新建一个java项目 2 ... -
hibernate 缓存 笔记
2009-11-02 12:00 1273hibernate一级缓存 一级缓存生命周期很短,它sess ... -
hibernate 缓存
2009-10-28 09:08 1142缓存可以简单的看成一个 Map ,通过 ...
相关推荐
深入理解hibernate缓存,不再惧怕hibernate缓存...
hibernate缓存机制 hibernate缓存机制 hibernate缓存机制
Hibernate缓存.docHibernate缓存.doc
Java Hibernate缓存深入详解
Hibernate 缓存 深入 详解 ITEye
Hibernate是一种面向Java环境的ORM工具。系统地分析了Hibernate的缓存结构,并描述了二级缓存的查询过程、缓存策略;同时总结了二级缓存使用中的一些限制,以及使用二级缓存的优化策略。
关于hibernate缓存的一个ppt课件,60+幻灯片,有需要的可以看一下
Hibernate缓存,性能优化
Hibernate缓存原理及调优策略 Hibernate缓存原理调优策略
Hibernate缓存深入详解,很好的缓存原理参考资料
Hibernate缓存的资料 Hibernate缓存机制对Hibernate的性能发挥一直处于一个极其重要的作用,它是持久层性能提升的关键。 hibernate缓存在应用系统中的位置 Hibernate缓存介于Hibernate应用和数据库之间,缓存...
关于hibernate缓存的讲解,以及缓存的优化。讲的非常透彻,对于项目中Hibernate缓存的优化会有很大帮助!
避免项目麻烦,禁用 hibernate 缓存
hibernate的缓存机制以及优化策略
hibernate缓存深入详解
首先说下Hibernate缓存的作用(即为什么要用缓存机制),然后再具体说说Hibernate中缓存的分类情况,最后可以举个具体的例子。 Hibernate缓存的作用: Hibernate是一个持久层框架
Hibernate二级缓存Hibernate二级缓存Hibernate二级缓存Hibernate二级缓存Hibernate二级缓存