我的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>
休眠配置
private static 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)
答案 0 :(得分:2)
因此,这是一个ClassLoader问题,可能与应用程序热重新生成时仍在运行的过时池有关。以下是一些建议:
确保在应用程序关闭时,某些挂钩中的休眠SessionFactory干净地关闭(),例如在SessionContextListener中。 close()SessionFactory应该清理池,而它所需的类仍然是活动的。这是最好的事情,因为除了您看到的消息之外,如果您在应用程序重新启动后从旧的应用程序实例中离开池,则会泄漏资源(线程,连接)。
升级到c3p0-0.9.5-pre8,然后尝试将hibernate.c3p0.contextClassLoaderSource
设置为library
。请参阅http://www.mchange.com/projects/c3p0/#contextClassLoaderSource确保将c3p0的两个jar文件放在应用程序服务器级别的lib目录中,而不是放在war文件或其他存档的子目录中。