【问题标题】:Failed to destroy resource: com.mchange.v2.c3p0.impl.NewPooledConnection@67a781cc销毁资源失败:com.mchange.v2.c3p0.impl.NewPooledConnection@67a781cc
【发布时间】:2014-06-30 02:07:43
【问题描述】:

我的 c3p0 配置如下,有时我会在控制台中收到以下错误消息。为什么我会收到这个?

        <property name="hibernate.c3p0.min_size">5</property>
        <property name="hibernate.c3p0.max_size">100</property>
        <property name="hibernate.c3p0.timeout">300</property>
        <property name="hibernate.c3p0.max_statements">50</property>
        <property name="hibernate.c3p0.idle_test_period">3000</property>
        <property name="current_session_context_class">thread</property>
        <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>

休眠配置

私有静态SessionFactory sessionFactory = buildSessionFactory();

private static SessionFactory buildSessionFactory() {
    try {
        System.err.println("in session Facotry");
        Configuration configuration = new Configuration();
        return configuration.configure().buildSessionFactory(
                new StandardServiceRegistryBuilder().applySettings(configuration.getProperties())
                .build());
    } catch (HibernateException ex) {
        System.err.println("Initial SessionFactory creation failed." + ex);
        throw new ExceptionInInitializerError(ex);
    }
}

public static SessionFactory getSessionFactory() {
    return sessionFactory;
}

错误

INFO:   WARN - Failed to destroy resource: com.mchange.v2.c3p0.impl.NewPooledConnection@67a781cc
 30 Jun 2014 11:57:59java.lang.IllegalStateException: This web container has not yet been started
    at org.glassfish.web.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1652)
    at org.glassfish.web.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1611)
    at com.mchange.v2.c3p0.stmt.GooGooStatementCache.synchronousDestroyStatement(GooGooStatementCache.java:413)
    at com.mchange.v2.c3p0.stmt.GooGooStatementCache.closeAll(GooGooStatementCache.java:351)
    at com.mchange.v2.c3p0.impl.NewPooledConnection.closeAllCachedStatements(NewPooledConnection.java:598)
    at com.mchange.v2.c3p0.impl.NewPooledConnection.close(NewPooledConnection.java:468)
    at com.mchange.v2.c3p0.impl.NewPooledConnection.close(NewPooledConnection.java:191)
    at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.destroyResource(C3P0PooledConnectionPool.java:470)
    at com.mchange.v2.resourcepool.BasicResourcePool$1DestroyResourceTask.run(BasicResourcePool.java:964)
    at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:547)

【问题讨论】:

    标签: java hibernate glassfish c3p0


    【解决方案1】:

    因此,这是一个 ClassLoader 问题,可能与应用程序热部署时仍在运行的陈旧池有关。以下是一些建议:

    1. 确保您的休眠 SessionFactory 在您的应用程序关闭时在某个挂钩中干净地关闭(),例如在 SessionContextListener 中。关闭() SessionFactory 应该在它需要的类仍然存在时清理池。这是最好的做法,因为除了您看到的消息之外,如果您在应用重新启动后让来自旧应用实例的池保持活动状态,那么您就是在泄漏资源(线程、连接)。

    2. 升级到 c3p0-0.9.5-pre8,并尝试将 hibernate.c3p0.contextClassLoaderSource 设置为 library。请参阅http://www.mchange.com/projects/c3p0/#contextClassLoaderSource 确保将 c3p0 的两个 jar 文件放在应用程序服务器级别的 lib 目录中,而不是放在 war 文件或其他存档的附属目录中。

    【讨论】:

    • 我包含了hibernate配置供您参考,您将hibernate.c3p0 .....设置为库是什么意思?"
    • hibernate.c3p0. 可用于在您的休眠配置中设置任意 c3p0 配置参数。因此将hibernate.c3p0.contextClassLoaderSource 设置为library 将设置该参数。请参阅链接以了解其含义。 (但它是新的;您需要确保您使用的是 c3p0-0.9.5-pre8。)
    • 您设置了一个 SessionFactory,但是如果您的应用程序热重新部署,您是否曾经将其拆除?它看起来不像,这很可能是你的问题。你什么时候打电话给sessionFactory.close()
    猜你喜欢
    • 1970-01-01
    • 2014-09-05
    • 1970-01-01
    • 2021-06-01
    • 2022-07-13
    • 2017-09-23
    • 2017-12-18
    • 2016-07-23
    • 1970-01-01
    相关资源
    最近更新 更多