源码分析
在 Factory中
private static final ThreadLocal threadLocal = new ThreadLocal();
的使用 可以参考
http://www.java3z.com/cwbwebhome/article/article2a/275.jsp?id=324线程安全
Session session = (Session) threadLocal.get();
if (session == null) {
if (sessionFactory == null) {
try {
cfg.configure(CONFIG_FILE_LOCATION);
sessionFactory = cfg.buildSessionFactory();
}
catch (Exception e) {
System.err.println("%%%% Error Creating SessionFactory %%%%");
e.printStackTrace();
}
}
session = sessionFactory.openSession();
threadLocal.set(session);
}
return session;