5

Hibernate3ORMを使用してJavastruts2フレームワークWebアプリケーションに取り組んでいます。データベースとしてmysqlを使用します。

ログにいくつかのDB関連の例外が見つかりました。データベースへの接続は、設定された時間より前にタイムアウトになります。これが私たちが見つけたコモンズの例外です。

104343235 [pool-6-thread-19] ERROR org.hibernate.util.JDBCExceptionReporter  - The last packet successfully received from the server was 100,838,460 milliseconds ago.  The last packet sent successfully to the server was 100,838,461 milliseconds ago. is longer than the server configured value of 'wait_timeout'. You should consider either expiring and/or testing connection validity before use in your application, increasing the server configured values for client timeouts, or using the Connector/J connection property 'autoReconnect=true' to avoid this problem.

org.hibernate.exception.JDBCConnectionException: could not execute query
    at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:99)
    at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
    at org.hibernate.loader.Loader.doList(Loader.java:2536)
    at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2276)
    at org.hibernate.loader.Loader.list(Loader.java:2271)
    at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:452)
    at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:363)
    at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:196)
    at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1268)
    at org.hibernate.impl.QueryImpl.list(QueryImpl.java:102)
    at com.myproject.model.dao.entities.EntitiesDAO.getByIds(EntitiesDAO.java:148)

Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully received from the server was 100,838,460 milliseconds ago.  The last packet sent successfully to the server was 100,838,461 milliseconds ago. is longer than the server configured value of 'wait_timeout'. You should consider either expiring and/or testing connection validity before use in your application, increasing the server configured values for client timeouts, or using the Connector/J connection property 'autoReconnect=true' to avoid this problem.
    at sun.reflect.GeneratedConstructorAccessor345.newInstance(Unknown Source)104343242 [pool-6-thread-16] ERROR org.hibernate.util.JDBCExceptionReporter  - The last packet successfully received from the server was 100,838,544 milliseconds ago.  The last packet sent successfully to the server was 100,838,544 milliseconds ago. is longer than the server configured value of 'wait_timeout'. You should consider either expiring and/or testing connection validity before use in your application, increasing the server configured values for client timeouts, or using the Connector/J connection property 'autoReconnect=true' to avoid this problem.
104343242 [pool-6-thread-16] ERROR org.hibernate.util.JDBCExceptionReporter  - The last packet successfully received from the server was 100,838,544 milliseconds ago.  The last packet sent successfully to the server was 100,838,544 milliseconds ago. is longer than the server configured value of 'wait_timeout'. You should consider either expiring and/or testing connection validity before use in your application, increasing the server configured values for client timeouts, or using the Connector/J connection property 'autoReconnect=true' to avoid this problem.

at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:525)
    at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
    at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1117)
    at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:3829)
    at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2449)
    at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2629)
    at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2719)
    at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2155)
    at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:2318)
    at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeQuery(NewProxyPreparedStatement.java:76)
    at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:208)
    at org.hibernate.loader.Loader.getResultSet(Loader.java:1953)
    at org.hibernate.loader.Loader.doQuery(Loader.java:802)
    at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:274)
    at org.hibernate.loader.Loader.doList(Loader.java:2533)
    ... 21 more

この問題の一時的な修正として、毎日アプリサーバーを再起動しています。

どんな助けでも大歓迎です。

4

2 に答える 2

5

これは、MySQLサーバーがタイムアウト後にアクティビティなしで接続を終了するために発生します。dbcp構成に数行追加する必要があります。次のパラメーターを追加してみてください。

validationQuery="SELECT 1"
testOnBorrow="true

仕組み:接続プールは、接続を返す前にvalidationQueryの実行を試みます。validateQuesryが失敗した場合、dbcpは接続を破棄し、新しい接続を作成して返します。

次に例を示します。

<Resource   name="jdbc/cooldatabase"
            description="Strandls.com license database"
            auth="Container"
            type="javax.sql.DataSource"
            factory="org.apache.tomcat.dbcp.dbcp.BasicDataSourceFactory"
            driverClassName="com.mysql.jdbc.Driver"
            url="jdbc:mysql://localhost:3306/cooldatabase?autoReconnect=true"
            username="cooluser"
            password="coolpassword"
            initialSize="0"
            maxActive="20"
            maxIdle="10"
            minIdle="0"
            maxWait="-1"
            validationQuery="SELECT 1"
            testOnBorrow="true"
            poolPreparedStatements="true"
            removeAbandoned="true"
            removeAbandonedTimeout="60"
            logAbandoned="true"/>

あなたはここで完全な詳細を見つけることができます:http://amitcodes.wordpress.com/2008/07/26/16/

于 2012-10-29T04:01:21.803 に答える
1

Hibernate で接続プールを使用します。例c3p0 : https://community.jboss.org/wiki/HowToConfigureTheC3P0ConnectionPool

于 2012-10-29T09:54:03.493 に答える