I get Can't get connection, pool error Timeout waiting for an unoccupied object, When I try to create more than 250 threads in my web application

Possible duplicate:
Connection pool exception: connection cannot be received, pool error. Timeout waiting for an unoccupied object

I get Can't get connection, pool error Timeout waiting for idle object error, When I try to create more than 250 threads in my web application. I am building a web application using JSF 2.0 and Hibernate.

I tried with modified hibernate.xml, server.xml, context.xml and also mysql properties.

Next up - I get.

WARN (JDBCExceptionReporter.java:233) - SQL Error: 0, SQLState: null ERROR (JDBCExceptionReporter.java:234) - Cannot get a connection, pool error Timeout waiting for idle object ERROR (BaseServlet.java:301) - ******** java.lang.Thread.getStackTrace(Thread.java:1426) Caused by: org.hibernate.exception.GenericJDBCException: Cannot open connection org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:140) org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:128) org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66) org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:52) org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:449) org.hibernate.jdbc.ConnectionManager.getConnection(ConnectionManager.java:167) org.hibernate.jdbc.JDBCContext.connection(JDBCContext.java:160) org.hibernate.transaction.JDBCTransaction.begin(JDBCTransaction.java:81) org.hibernate.impl.SessionImpl.beginTransaction(SessionImpl.java:1473) sun.reflect.GeneratedMethodAccessor378.invoke(Unknown Source) Caused by: org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot get a connection, pool error Timeout waiting for idle object org.apache.tomcat.dbcp.dbcp.PoolingDataSource.getConnection(PoolingDataSource.java:114) org.apache.tomcat.dbcp.dbcp.BasicDataSource.getConnection(BasicDataSource.java:1044) org.hibernate.connection.DatasourceConnectionProvider.getConnection(DatasourceConnectionProvider.java:92) org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:446) org.hibernate.jdbc.ConnectionManager.getConnection(ConnectionManager.java:167) org.hibernate.jdbc.JDBCContext.connection(JDBCContext.java:160) org.hibernate.transaction.JDBCTransaction.begin(JDBCTransaction.java:81) org.hibernate.impl.SessionImpl.beginTransaction(SessionImpl.java:1473) sun.reflect.GeneratedMethodAccessor378.invoke(Unknown Source) sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) Caused by: java.util.NoSuchElementException: Timeout waiting for idle object org.apache.tomcat.dbcp.pool.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:1144) org.apache.tomcat.dbcp.dbcp.PoolingDataSource.getConnection(PoolingDataSource.java:106) org.apache.tomcat.dbcp.dbcp.BasicDataSource.getConnection(BasicDataSource.java:1044) org.hibernate.connection.DatasourceConnectionProvider.getConnection(DatasourceConnectionProvider.java:92) org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:446) org.hibernate.jdbc.ConnectionManager.getConnection(ConnectionManager.java:167) org.hibernate.jdbc.JDBCContext.connection(JDBCContext.java:160) org.hibernate.transaction.JDBCTransaction.begin(JDBCTransaction.java:81) org.hibernate.impl.SessionImpl.beginTransaction(SessionImpl.java:1473) sun.reflect.GeneratedMethodAccessor378.invoke(Unknown Source) 

Please, if you have any idea about this, help me ......

+6
source share
2 answers

You may have set a timeout for dead connections, and some requests take longer than that. This means that your pool has removed the busy connection as dead from the pool and requested another from the DB - until the DB pulls out the plug.

To debug this, enable logging for the connection pool so you can see when it requests new connections.

also check mysql connection settings. and try closing the connection when you finish with your db coz next time (outside the maxConnectionAge limit) that the connection state will be dead .

+4
source

I had such a problem before, what you need to do is close hibernate sessions when you are done with it.

eg.

 Session sess = factory.openSession(); Transaction tx; try { tx = sess.beginTransaction(); //do some work ... tx.commit(); } catch (Exception e) { if (tx!=null) tx.rollback(); throw e; } finally { sess.close(); // closing session } 
+4
source

Source: https://habr.com/ru/post/921738/


All Articles