一尘不染

Websphere因c3p0挂起

jsp

我正在将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中达到的最大游标错误。

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


阅读 310

收藏
2020-06-08

共1个答案

一尘不染

池正在等待连接。如果他们再也没有来过,那么您可能已经因为连接泄漏而将其耗尽。

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

2020-06-08