我的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)
最佳答案
因此,这是一个ClassLoader问题,可能与在热重新部署应用程序时仍在运行的旧池有关。这里有一些建议:
确保您的休眠SessionFactory在应用程序关闭时例如通过钩子干净地关闭()。在SessionContextListener中。 close()ing SessionFactory应该在其所需的类仍然存在时清理池。这是最好的做法,因为除了看到的消息外,如果在应用程序重新启动后仍保留旧应用程序实例的池处于活动状态,则会泄漏资源(线程,连接)。
升级到c3p0-0.9.5-pre8,然后尝试将hibernate.c3p0.contextClassLoaderSource
设置为library
。请参见http://www.mchange.com/projects/c3p0/#contextClassLoaderSource确保将c3p0的两个jar文件放置在应用程序服务器级别的lib目录中,而不是war文件或其他归档文件的子目录中。