无法加载com.mchange.v2.resourcepool.BasicResourcePool $ 1DestroyResourceTask。 java.lang.IllegalStateException

时间:2015-09-22 08:11:36

标签: java hibernate c3p0

我正在使用移动Web应用程序,对于我正在使用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>

1 个答案:

答案 0 :(得分:6)

因此,您正在进行tomcat热重新部署ClassLoader问题。

你应该做两件事:

  1. 确保在关闭应用程序时,您的Hibernate SessionFactory也会被close()编辑。这样做的最佳位置是ServletContextListener。否则,在热重新部署时,来自现在丢弃的应用程序的c3p0线程将继续运行。请参阅SessionFactory.close()

  2. 尝试使用here描述的设置,以防止对已失效ClassLoader的对象进行过度引用。您只需添加

  3. 即可
    <property name="hibernate.c3p0.privilegeSpawnedThreads">true</property>
    <property name="hibernate.c3p0.contextClassLoaderSource">library</property>
    

    到你的c3p0配置部分。

    (p.s。请确保您使用的是最近版本的c3p0。这些设置是新的。)