Hibernate 由于达到maxPoolSize,应用程序冻结
我的web应用程序冻结时出现问题。使用JConsole监控工具,我看到应用程序正在达到maxPoolSize。这导致应用程序冻结 系统上大约有20个用户,每个用户可以有多个web会话 下面是应用程序中的HttpServlet示例Hibernate 由于达到maxPoolSize,应用程序冻结,hibernate,connection-pooling,c3p0,Hibernate,Connection Pooling,C3p0,我的web应用程序冻结时出现问题。使用JConsole监控工具,我看到应用程序正在达到maxPoolSize。这导致应用程序冻结 系统上大约有20个用户,每个用户可以有多个web会话 下面是应用程序中的HttpServlet示例 public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { Session sess = null;
public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
Session sess = null;
Transaction tx = null;
try {
sess = RuntimeContext.getCurrentSession();
tx = sess.beginTransaction();
doingStuffWithSession(req, res, sess);
if (!tx.wasCommitted()) {
tx.commit();
}
} catch (Exception e) {
handleException(e, req, sess);
} finally {
if (sess != null && sess.isOpen() && tx != null && tx.isActive()) {
tx.rollback();
}
}
}
以下是我在c3p0中的hibernate属性:
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.SQLServerDialect"/>
<property name="hibernate.archive.autodetection" value="class, hbm"/>
<property name="hibernate.c3p0.min_size" value="20" />
<property name="hibernate.c3p0.max_size" value="200" />
<property name="hibernate.c3p0.timeout" value="300" />
<property name="hibernate.c3p0.max_statements" value="50" />
<property name="hibernate.c3p0.idle_test_period" value="3000" />
</properties>
看起来您是在打开会话(在您的运行时上下文中),而不是在每次使用时打开和关闭它们。会话包装连接;如果不关闭会话,将耗尽池中的资源。提交或回滚事务是不够的 您应该为每个客户端打开一个新会话,并在客户端完成后立即关闭它。请参见此处介绍的成语: