我遇到问题,我的网络应用程序冻结了。使用JConsole监视工具,我看到该应用程序正在达到maxPoolSize。这导致应用程序冻结。
系统上大约有20个用户,每个用户可以有多个网络会话。
这是应用程序中HttpServlet的一个示例。
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>
答案 0 :(得分:1)
看起来你正在打开Sessions(在你的RuntimeContext中),而不是在每次使用时打开和关闭它们。会话包装连接;如果你没有关闭你的会话,你将耗尽游泳池。提交或回滚交易是不够的。
您应该为每个客户端打开一个新会话,并在客户端完成后立即关闭它。见例如这里的成语:http://www.tutorialspoint.com/hibernate/hibernate_sessions.htm