2013-03-12 86 views
0

我遇到了问题,我的Web应用程序冻结了。使用JConsole监视工具,我发现应用程序正在达到maxPoolSize。这是导致应用程序冻结。由于达到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:

<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> 

回答

1

它看起来像你持有会话打开(在你的RuntimeContext在运行时),而不是打开和关闭()荷兰国际集团他们在每次使用时。会话包装连接;如果你不关闭你的会话,你会耗尽游泳池。承诺或回滚交易是不够的。

您应该为每个客户端打开一个新的会话,并在客户端完成后立即关闭它。见例如这里介绍的成语:http://www.tutorialspoint.com/hibernate/hibernate_sessions.htm

相关问题