簡體   English   中英

運行應用程序時引發線程“ Timer-0”中的異常

[英]Exception in thread “Timer-0” thrown when run the application

當我運行我的應用程序時,它可以運行,但會在控制台中引發如下異常:每次顯示不同的計時器號。 我使用的所有技術都標記有該問題。 如果您需要我分享除以下內容之外的代碼的任何其他部分,請告訴我。

    SEVERE:   Exception in thread "Timer-0"
SEVERE:   java.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.resourcepool.BasicResourcePool.checkIdleResources(BasicResourcePool.java:1481)
    at com.mchange.v2.resourcepool.BasicResourcePool.access$2000(BasicResourcePool.java:32)
    at com.mchange.v2.resourcepool.BasicResourcePool$CheckIdleResourcesTask.run(BasicResourcePool.java:1964)
    at java.util.TimerThread.mainLoop(Timer.java:555)
    at java.util.TimerThread.run(Timer.java:505)

hibernate.cfg.xml

 <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
    <property name="hibernate.connection.url">jdbc:mysql://localhost/test</property>
    <property name="hibernate.connection.username">root</property>
    <property name="hibernate.connection.password"></property>
    <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>

    <property name="show_sql">true</property>

    <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>
    <!-- Enable Hibernate's automatic session context management -->
    <property name="current_session_context_class">thread</property>

    <!-- Disable the second-level cache  -->
    <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>

HibernateUtil

    public class HibernateUtil {

    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;
    }

}

這是c3p0連接池庫,試圖在服務器完成啟動過程之前進行連接維護。

在全棧Java EE服務器(例如Glassfish,WildFly / JBossAS,WebLogic等)上,使用第三方連接池機制是多余的。

解決方案是

  1. 從應用程序中刪除所有與c3p0相關的jar(以及可能已添加到應用程序服務器的所有jar)
  2. 根據休眠配置在Glassfish中使用連接詳細信息定義數據源
  3. 將休眠配置屬性減少為:

     <property name="hibernate.connection.datasource">jndi name of the datasource you defined in step 2</property> <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property> <property name="show_sql">true</property> <!-- Enable Hibernate's automatic session context management --> <property name="current_session_context_class">thread</property> <!-- Disable the second-level cache --> <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property> 

請注意,Tomcat支持使用數據源,並且還具有自己的連接池實現。

除了HibernateUtil.class之外,是否還使用其他任何靜態初始化塊? 為了進行測試,請在HibernateUtil中更改所有異常,然后捕獲Throwable。

似乎在初始化Web應用程序和所有靜態初始化塊期間發生了錯誤。

從后台任務調用該異常,該任務的任務是清理資源,並且在完全初始化服務器之前啟動了該任務。

這不是由您的代碼引起的問題,它看起來像Glassfish作業未遵循正確的執行順序。

我建議您在Glassfish問題跟蹤器上提交問題報告並提供給他們:

  • 應用服務器版本
  • 操作系統版本
  • 應用程序配置文件

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM