0

我正在使用 WAS 7.1 以及 c3p0 (v 0.9.2.1) & hibernate (3.2.6ga)

使用几个小时后,Websphere 挂起,我在日志中看到此消息

[6/24/13 10:57:50:377 CEST] 00000031 ThreadMonitor W   WSVR0605W: Thread "WebContainer : 24" (00000048) has been active for 759356 milliseconds and may be hung.  There is/are 45 thread(s) in total in the server that may be hung.
    at java.lang.Object.wait(Native Method)
    at java.lang.Object.wait(Object.java:196)
    at com.mchange.v2.resourcepool.BasicResourcePool.awaitAcquire(BasicResourcePool.java:776)
    at com.mchange.v2.resourcepool.BasicResourcePool.checkoutResource(BasicResourcePool.java:198)
    at com.mchange.v2.resourcepool.BasicResourcePool.checkoutResource(BasicResourcePool.java:170)
    at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:172)
    at com.mchange.v2.c3p0.PoolBackedDataSource.getConnection(PoolBackedDataSource.java:58)
    at org.hibernate.connection.C3P0ConnectionProvider.getConnection(C3P0ConnectionProvider.java:56)
    at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:423)
    at org.hibernate.jdbc.ConnectionManager.getConnection(ConnectionManager.java:144)
    at org.hibernate.jdbc.JDBCContext.connection(JDBCContext.java:119)
    at org.hibernate.transaction.JDBCTransaction.begin(JDBCTransaction.java:57)
    at org.hibernate.impl.SessionImpl.beginTransaction(SessionImpl.java:1326)
    at com.aaa.in.bbb.effort.daoImpl.GRDAO.getGroupList(GRDAO.java:60)
    at com.aaa.in.bbb.effort.delegate.GRBean.getGroupList(GRBean.java:40)
    at com.aaa.in.bbb.effort.action.GRAction.execute(GRAction.java:74)
    at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:419)
    at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:224)
    at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1194)
    at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:414)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:718)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:831)
    at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1658)
    at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:940)
    at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:503)
    at com.ibm.ws.webcontainer.servlet.ServletWrapperImpl.handleRequest(ServletWrapperImpl.java:181)
    at com.ibm.ws.webcontainer.webapp.WebApp.handleRequest(WebApp.java:3954)
    at com.ibm.ws.webcontainer.webapp.WebGroup.handleRequest(WebGroup.java:276)
    at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:942)
    at com.ibm.ws.webcontainer.WSWebContainer.handleRequest(WSWebContainer.java:1592)
    at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:186)
    at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:453)
    at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewRequest(HttpInboundLink.java:515)
    at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.processRequest(HttpInboundLink.java:306)
    at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.ready(HttpInboundLink.java:277)
    at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.sendToDiscriminators(NewConnectionInitialReadCallback.java:214)
    at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.complete(NewConnectionInitialReadCallback.java:113)
    at com.ibm.ws.tcp.channel.impl.AioReadCompletionListener.futureCompleted(AioReadCompletionListener.java:165)
    at com.ibm.io.async.AbstractAsyncFuture.invokeCallback(AbstractAsyncFuture.java:217)
    at com.ibm.io.async.AsyncChannelFuture.fireCompletionActions(AsyncChannelFuture.java:161)
    at com.ibm.io.async.AsyncFuture.completed(AsyncFuture.java:138)
    at com.ibm.io.async.ResultHandler.complete(ResultHandler.java:204)
    at com.ibm.io.async.ResultHandler.runEventProcessingLoop(ResultHandler.java:775)
    at com.ibm.io.async.ResultHandler$2.run(ResultHandler.java:905)
    at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1646)

我不知道为什么会话没有关闭。这是会话代码

public class HibernateUtil {
    private static final SessionFactory sessionFactory; 
    static {
        try {
            Context ctx = new InitialContext();
            Object obj = ctx.lookup("HibernateSessionFactory");         
            sessionFactory = (SessionFactory) obj;
        } catch (Throwable ex) {

            System.out.println("Initial SessionFactory creation failed: "
                    + ex.getMessage());
            throw new ExceptionInInitializerError(ex);
        }
    }

    public static final ThreadLocal hibernateSession = new ThreadLocal();

    public static Session currentSession() {
        Session s = (Session) sessionFactory.openSession();     
        hibernateSession.set(s); 
        return s;
    }
    public static void closeSession() {
        Session s = (Session) hibernateSession.get();
        try {
            if(s != null)
            {
              hibernateSession.set(null);
              s.close();
              System.out.println("s!=null");              
            }
        } catch (HibernateException e) {            
            e.printStackTrace();
            System.out.println("Error occured in closesession()");
        }
        finally
        {
            s=null;
        }

    }
    public static void closeSession(Session session) {
         try {
            if(session != null)
             {
                session.flush();
                hibernateSession.set(null);
                session.close();
                session=null; 

             }
        } catch (HibernateException e) {            
            e.printStackTrace();
            System.out.println("Error occured in closesession(session)");

        }
    }   
}

我检查了代码,并且有关闭会话的请求,但不知何故会话本身没有被 C3P0 释放

只有在我引入连接池之后才会出现问题。我必须引入连接池的原因是为了解决 Oracle 11 中达到的最大游标错误(请参阅JSP + Hibernate 中达到的最大游标错误)

有人遇到过这个错误吗?任何指针?

4

1 回答 1

1

池正在等待连接。如果他们从来没有来过,那么您很可能由于连接泄漏而用尽了它。

请使用 c3p0 配置参数unreturnedConnectionTimeoutdebugUnreturnedConnectionStackTraces调试泄漏。请参阅此处的讨论。

于 2013-06-24T10:48:12.717 回答