ThreadLocal 在hibernate中应用
2016-05-16 22:14
323 查看
private static final ThreadLocal threadSession = new ThreadLocal(); public static Session getSession() throws InfrastructureException { Session s = (Session) threadSession.get(); try { if (s == null) { s = getSessionFactory().openSession(); threadSession.set(s); } } catch (HibernateException ex) { throw new InfrastructureException(ex); } return s; }
相关文章推荐
- String、StringBuffer和StringBuilder
- 结合testng实现用例失败重跑
- java的seek()函数
- 面试要回顾的知识
- Struts 2 入门
- 多线程-线程间通信-多生产者多消费者示例
- 按位异或 !
- JAVA第一步工作 classpath、path、JAVA_HOME的作用及JAVA环境变量配置等
- 小代码 F
- 你好哇,程序员 - me 跳槽经验说
- 201. Bitwise AND of Numbers Range
- 正则表达式大全
- 数据结构实验之链表七:单链表中重复元素的删除
- Unity 脚本生命周期流程图
- 设计模式之装饰者模式
- Intent
- Android Studio 魅族手机调试LogCat不显示解决方法
- TCP连接的建立与终止
- 338. Counting Bits
- JavaWEB中web.xml和servlet不得不说的秘密。