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

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

?