-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Timout when many selects executed
PostPosted: Fri Jul 10, 2009 8:55 am 
Newbie

Joined: Wed Feb 13, 2008 6:38 am
Posts: 5
Location: Germany - Leipzig
I work with Hibernate and Spring. I have written following code.

Code:
         return (CurrentStatus) getHibernateTemplate().execute(new HibernateCallback()
         {
            @SuppressWarnings("unchecked")
            public Object doInHibernate(Session session) throws HibernateException, SQLException
            {
               String queryString = "SELECT werk, format, status, intern, count(*) as anzahl from sstatus as status where werk = ? and richtung = ? and format = ? and status = ? and intern = ? and updated between ? and ? group by werk, format,status, intern order by werk, format, status, intern";
               SQLQuery q = session.createSQLQuery(queryString);
               q.setInteger(0, werk.getId());
               q.setString(1, richtung);
               q.setString(2, format);
               q.setString(3, status);
               q.setBoolean(4, intern);
               q.setDate(5, anfang);
               q.setDate(6, ende);
               q.setCacheable(false);
               q.addEntity("status", CurrentStatus.class);
               List<CurrentStatus> o = q.list();
               if (o.size() == 0) return new CurrentStatus(new CurrentStatusId(werk, format, status, richtung, intern), 0);
               else
               {
                  CurrentStatus cs = o.get(0);
                  return cs;
               }
            }
         });



This function was executed many times to collect some statistic data in a matrix, but after a few times I become following Message.

Code:
2009-07-10 14:40:55,428  WARN (org.hibernate.util.JDBCExceptionReporter:77) - SQL Error: 0, SQLState: null
2009-07-10 14:40:55,428 ERROR (org.hibernate.util.JDBCExceptionReporter:78) - An attempt by a client to checkout a Connection has timed out.
2009-07-10 14:40:55,428  WARN (org.hibernate.util.JDBCExceptionReporter:77) - SQL Error: 0, SQLState: null
2009-07-10 14:40:55,428 ERROR (org.hibernate.util.JDBCExceptionReporter:78) - An attempt by a client to checkout a Connection has timed out.
10.07.2009 14:40:55 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from class path resource [org/springframework/jdbc/support/sql-error-codes.xml]
10.07.2009 14:40:55 org.springframework.jdbc.support.SQLErrorCodesFactory <init>
INFO: SQLErrorCodes loaded: [DB2, Derby, H2, HSQL, Informix, MS-SQL, MySQL, Oracle, PostgreSQL, Sybase]
10.07.2009 14:41:05 org.springframework.jdbc.support.SQLErrorCodesFactory getErrorCodes
WARNUNG: Error while extracting database product name - falling back to empty error codes
org.springframework.jdbc.support.MetaDataAccessException: Could not get Connection for extracting meta data; nested exception is org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is java.sql.SQLException: An attempt by a client to checkout a Connection has timed out.
   at org.springframework.jdbc.support.JdbcUtils.extractDatabaseMetaData(JdbcUtils.java:198)
   at org.springframework.jdbc.support.JdbcUtils.extractDatabaseMetaData(JdbcUtils.java:225)
   at org.springframework.jdbc.support.SQLErrorCodesFactory.getErrorCodes(SQLErrorCodesFactory.java:216)
   at org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.setDataSource(SQLErrorCodeSQLExceptionTranslator.java:147)
   
   .
   .
   .
   .
   
Caused by: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is java.sql.SQLException: An attempt by a client to checkout a Connection has timed out.
   at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:82)
   at org.springframework.jdbc.support.JdbcUtils.extractDatabaseMetaData(JdbcUtils.java:185)
   ... 87 more
Caused by: java.sql.SQLException: An attempt by a client to checkout a Connection has timed out.
   at com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.java:106)
   at com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.java:65)
   at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:527)
   at com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource.getConnection(AbstractPoolBackedDataSource.java:128)
   at org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:113)
   at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:79)
   ... 88 more
Caused by: com.mchange.v2.resourcepool.TimeoutException: A client timed out while waiting to acquire a resource from com.mchange.v2.resourcepool.BasicResourcePool@86b376 -- timeout at awaitAvailable()
   at com.mchange.v2.resourcepool.BasicResourcePool.awaitAvailable(BasicResourcePool.java:1317)
   at com.mchange.v2.resourcepool.BasicResourcePool.prelimCheckoutResource(BasicResourcePool.java:557)
   at com.mchange.v2.resourcepool.BasicResourcePool.checkoutResource(BasicResourcePool.java:477)
   at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:525)
   


each select runs only arround 10ms why I become this timeout?

my configuration is:
Code:
      <property name="checkoutTimeout" value="5000" />
      <property name="initialPoolSize" value="5" />
      <property name="minPoolSize" value="5" />
      <property name="maxPoolSize" value="40" />
      <property name="maxIdleTime" value="18000" />
      <property name="acquireIncrement" value="5" />
      <property name="maxIdleTimeExcessConnections" value="1800" />


Does anyone have a tip why hibernate become an error? In the Postgres Monitor I see only one Session is used all other are idle. I try different Pool sizes but the Error is still the same.

_________________
My Java Developer Blog
Mein Wein Forum


Top
 Profile  
 
 Post subject: Re: Timout when many selects executed
PostPosted: Tue Jul 14, 2009 9:50 am 
Newbie

Joined: Wed Feb 13, 2008 6:38 am
Posts: 5
Location: Germany - Leipzig
i don't know the reason, but surrounding the function calls with a TransactionTemplate helps to fix the problem.

Code:
      transactionTemplate.execute(new TransactionCallback() {

         public Object doInTransaction(TransactionStatus arg0) {

_________________
My Java Developer Blog
Mein Wein Forum


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.