首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > 其他数据库 >

数据库连接开启与封闭-ThreadLocal的应用

2013-08-10 
数据库连接开启与关闭-ThreadLocal的应用代码如下: private static final ThreadLocal threadSession ne

数据库连接开启与关闭-ThreadLocal的应用

代码如下:

 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;      }  

?

热点排行