读书人

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

发布时间: 2013-08-10 21:14:06 作者: rapoo

数据库连接开启与关闭-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;      }  

?

读书人网 >其他数据库

热点推荐