线程“com.mchange.v2.async.ThreadPoolAsynchronousRunner $ PoolThread-#0”中的异常

时间:2015-11-03 06:40:29

标签: java spring hibernate c3p0

我最近在日志中收到以下消息,然后是Application Server崩溃。我不知道该怎么做,并且非常感谢任何指导。

Exception in thread "Task-Thread-for-com.mchange.v2.async.ThreadPerTaskAsynchronousRunner@6a1a2b5b" java.lang.OutOfMemoryError: Direct buffer memory
at java.nio.Bits.reserveMemory(Bits.java:658)
at java.nio.DirectByteBuffer.<init>(DirectByteBuffer.java:123)
at java.nio.ByteBuffer.allocateDirect(ByteBuffer.java:306)
at com.amazon.jdbc.communications.channels.MessagesSocketChannel.<init>(Unknown Source)
at com.amazon.redshift.client.PGClient.connect(Unknown Source)
at com.amazon.redshift.client.PGClient.<init>(Unknown Source)
at com.amazon.redshift.core.PGJDBCConnection.connect(Unknown Source)
at com.amazon.jdbc.common.BaseConnectionFactory.doConnect(Unknown Source)
at com.amazon.jdbc.common.AbstractDriver.connect(Unknown Source)
at com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:134)
at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:182)
at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:171)
at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:137)
at com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1014)
at com.mchange.v2.resourcepool.BasicResourcePool.access$800(BasicResourcePool.java:32)
at com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask.run(BasicResourcePool.java:1810)
at com.mchange.v2.async.ThreadPerTaskAsynchronousRunner$TaskThread.run(ThreadPerTaskAsynchronousRunner.java:255)

Exception in thread "com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#2" java.lang.NoClassDefFoundError: com/amazon/redshift/exceptions/PGJDBCMessageKey
at com.amazon.redshift.client.PGClient.connect(Unknown Source)
at com.amazon.redshift.client.PGClient.<init>(Unknown Source)
at com.amazon.redshift.core.PGJDBCConnection.connect(Unknown Source)
at com.amazon.jdbc.common.BaseConnectionFactory.doConnect(Unknown Source)
at com.amazon.jdbc.common.AbstractDriver.connect(Unknown Source)
at com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:134)
at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:182)
atcom.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:171)
at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:137)
at com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1014)
at com.mchange.v2.resourcepool.BasicResourcePool.access$800(BasicResourcePool.java:32)
at com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask.run(BasicResourcePool.java:1810)
at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:547)

我们正在使用Spring,hibernate和c3p0以及以下Configration

<bean id="redShiftDS" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
    <!-- access -->
    <property name="driverClass" value="com.amazon.redshift.jdbc41.Driver" />
    <property name="user">
            <value>${redshift.user}</value>
        </property>
        <property name="password">
            <value>${redshift.pwd}</value>
        </property>     

        <property name="jdbcUrl">
            <value>${redshift.URL}</value>
        </property>


    <!-- pool sizing -->
    <property name="initialPoolSize" value="3" />
    <property name="minPoolSize" value="6" />
    <property name="maxPoolSize" value="25" />
    <property name="acquireIncrement" value="3" />
    <property name="maxStatements" value="0" />

    <!-- retries -->
    <property name="acquireRetryAttempts" value="30" />
    <property name="acquireRetryDelay" value="1000" /> <!-- 1s -->
    <property name="breakAfterAcquireFailure" value="false" />

    <!-- refreshing connections -->
    <property name="maxIdleTime" value="180" /> <!-- 3min -->
    <property name="maxConnectionAge" value="10" /> <!-- 1h -->

    <!-- timeouts and testing -->
    <property name="checkoutTimeout" value="5000" /> <!-- 5s -->
    <property name="idleConnectionTestPeriod" value="60" /> <!-- 60 -->
    <property name="testConnectionOnCheckout" value="true" />
        <property name="testConnectionOnCheckin" value="true" />
</bean>
        <bean id="redShiftSessionFactory"
        class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
        <property name="dataSource">
            <ref bean="redShiftDS" />
        </property>
        <property name="packagesToScan" value="com.ghx.mi">
        </property>
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</prop>
                <prop key="hibernate.auto_close_session">true</prop>
                <prop key="hibernate.connection.autocommit">true</prop>
                <prop key="hibernate.temp.use_jdbc_metadata_defaults">false</prop>
                <prop key="hibernate.jdbc.batch_size">30</prop>
                <prop key="hibernate.show_sql">false</prop>
                 <prop key="hibernate.autoReconnect">true</prop>
                <prop key="hibernate.autoReconnectForPools">true</prop>    
                <prop key="hibernate.is-connection-validation-required">true</prop>
            </props>
        </property>
    </bean>

我们使用Java 7&amp; Tomcat 7.0

1 个答案:

答案 0 :(得分:0)

一些建议:

1)从CLASSPATH的角度来看,确保c3p0的jar文件位于相同的“位置”,因为应该包含com.amazon.redshift.exceptions.PGJDBCMessageKey的库(可能是你的RedshiftJDBC41-1.1.6.1006.jar)换句话说,不要将redshift jar放在应用程序服务器lib目录中,而是将c3p0的jar文件放在Web应用程序li​​b目录中,或类似的东西。它们在逻辑上应该是相同的CLASSPATH。

2)将以下属性添加到c3p0配置:

<property name="contextClassLoaderSource" value="library" />

这将确保c3p0线程尝试使用加载库的相同ClassLoader加载类,即与包含c3p0的逻辑CLASSPATH相同的逻辑CLASSPATH。 (见the docs。)

3)从

修复此问题
<property name="maxConnectionAge" value="10" /> <!-- 1h -->

到这个

<property name="maxConnectionAge" value="3600" /> <!-- 1h, really this time -->

10秒对于连接过期来说太快了太多,这将导致翻腾,内存压力和各种不当行为。