作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用一个移动网络应用程序,其中数据库部分我使用Hibernate
,连接池c3p0
,当我在开始工作正常,但是在执行了一些事务(例如选择、保存、更新)之后,我收到以下异常,我不知道为什么会发生,
Sep 22, 2015 12:40:06 PM org.apache.catalina.loader.WebappClassLoader loadClass
INFO: Illegal access: this web application instance has been stopped already. Could not load com.mchange.v2.resourcepool.BasicResourcePool$1DestroyResourceTask. The eventual following stack trace is caused by an error thrown for debugging purposes as well as to attempt to terminate the thread which caused the illegal access, and has no functional impact.
java.lang.IllegalStateException
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1562)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1521)
at com.mchange.v2.resourcepool.BasicResourcePool.destroyResource(BasicResourcePool.java:1040)
at com.mchange.v2.resourcepool.BasicResourcePool.removeResource(BasicResourcePool.java:1507)
at com.mchange.v2.resourcepool.BasicResourcePool.removeResource(BasicResourcePool.java:1477)
at com.mchange.v2.resourcepool.BasicResourcePool.cullExpired(BasicResourcePool.java:1565)
at com.mchange.v2.resourcepool.BasicResourcePool.access$1900(BasicResourcePool.java:44)
at com.mchange.v2.resourcepool.BasicResourcePool$CullTask.run(BasicResourcePool.java:2089)
at java.util.TimerThread.mainLoop(Timer.java:512)
at java.util.TimerThread.run(Timer.java:462)
Exception in thread "C3P0PooledConnectionPoolManager[identityToken->2sa3m19b1vnwmg61s8v1zi|5363e54]-AdminTaskTimer" java.lang.NoClassDefFoundError: com/mchange/v2/resourcepool/BasicResourcePool$1DestroyResourceTask
at com.mchange.v2.resourcepool.BasicResourcePool.destroyResource(BasicResourcePool.java:1040)
at com.mchange.v2.resourcepool.BasicResourcePool.removeResource(BasicResourcePool.java:1507)
at com.mchange.v2.resourcepool.BasicResourcePool.removeResource(BasicResourcePool.java:1477)
at com.mchange.v2.resourcepool.BasicResourcePool.cullExpired(BasicResourcePool.java:1565)
at com.mchange.v2.resourcepool.BasicResourcePool.access$1900(BasicResourcePool.java:44)
at com.mchange.v2.resourcepool.BasicResourcePool$CullTask.run(BasicResourcePool.java:2089)
at java.util.TimerThread.mainLoop(Timer.java:512)
at java.util.TimerThread.run(Timer.java:462)
Caused by: java.lang.ClassNotFoundException: com.mchange.v2.resourcepool.BasicResourcePool$1DestroyResourceTask
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1676)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1521)
... 8 more
Hibernate.cfg.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<!-- Database connection settings -->
<property name="connection.driver_class">org.postgresql.Driver</property>
<property name="connection.username">postgres</property>
<property name="connection.password">admin</property>
<property name="connection.url">jdbc:postgresql://localhost:5432/db</property>
<!-- SQL dialect -->
<property name="dialect">com.bss.util.PostgreSQLDialectCustom</property>
<!-- Enable Hibernate's automatic session context management -->
<property name="current_session_context_class">thread</property>
<!-- Echo all executed SQL to stdout -->
<property name="show_sql">true</property>
<!-- Use the C3P0 connection pool provider -->
<property name="hibernate.c3p0.min_size">5</property>
<property name="hibernate.c3p0.max_size">20</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>
<mapping class="com.bss.model.TestUser"/>
<mapping class="com.bss.model.ItappFriendlist"/>
<mapping class="com.bss.model.ItappFriendlistPK"/>
<mapping class="com.bss.model.User"/>
<mapping class="com.bss.model.UserSession"/>
</session-factory>
</hibernate-configuration>
最佳答案
所以,您遇到了 tomcat 热重新部署 ClassLoader
问题。
您应该做两件事:
确保当您的应用程序关闭时,您的 Hibernate SessionFactory
也会被 close()
编辑。执行此操作的最佳位置是 ServletContextListener。否则,在热重新部署时,现已废弃的应用程序中的 c3p0 线程将继续运行。请参阅SessionFactory.close()
尝试描述的设置 here防止从失效的ClassLoader
中对对象进行杂散引用。您只需添加
<property name="hibernate.c3p0.privilegeSpawnedThreads">true</property>
<property name="hibernate.c3p0.contextClassLoaderSource">library</property>
<小时/>
到你的c3p0配置部分。
(请确保您使用的是最新版本的 c3p0。这些设置是新的。)
关于java - 无法加载 com.mchange.v2.resourcepool.BasicResourcePool$1DestroyResourceTask。 java.lang.IllegalStateException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32711728/
我是一名优秀的程序员,十分优秀!