2014-09-11 29 views
3

我有一個標準的Java應用程序,它在關閉時掛起。我一直試圖找出是什麼導致它掛起,但到目前爲止我還沒有發現任何有用的東西。Java應用程序在停止時掛起

這是當我曾試圖阻止該應用程序的線程轉儲:

2014-09-11 11:49:31 
Full thread dump Java HotSpot(TM) Client VM (24.51-b03 mixed mode): 

"DestroyJavaVM" prio=6 tid=0x19fbbc00 nid=0x22f8 waiting on condition [0x00000000] 
    java.lang.Thread.State: RUNNABLE 

"pool-3-thread-1" prio=6 tid=0x19fbdc00 nid=0x13c4 waiting on condition [0x2721f000] 
    java.lang.Thread.State: TIMED_WAITING (parking) 
     at sun.misc.Unsafe.park(Native Method) 
     - parking to wait for <0x0affc368> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject) 
     at java.util.concurrent.locks.LockSupport.parkNanos(Unknown Source) 
     at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.awaitNanos(Unknown Source) 
     at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(Unknown Source) 
     at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(Unknown Source) 
     at java.util.concurrent.ThreadPoolExecutor.getTask(Unknown Source) 
     at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) 
     at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) 
     at java.lang.Thread.run(Unknown Source) 

"pool-4-thread-1" prio=6 tid=0x19fbd400 nid=0x2010 waiting on condition [0x2729f000] 
    java.lang.Thread.State: TIMED_WAITING (parking) 
     at sun.misc.Unsafe.park(Native Method) 
     - parking to wait for <0x0ad38c80> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject) 
     at java.util.concurrent.locks.LockSupport.parkNanos(Unknown Source) 
     at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.awaitNanos(Unknown Source) 
     at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(Unknown Source) 
     at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(Unknown Source) 
     at java.util.concurrent.ThreadPoolExecutor.getTask(Unknown Source) 
     at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) 
     at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) 
     at java.lang.Thread.run(Unknown Source) 

"HSQLDB Timer @1e75cb0" daemon prio=6 tid=0x19fbd000 nid=0x8f4 in Object.wait() [0x2709f000] 
    java.lang.Thread.State: TIMED_WAITING (on object monitor) 
     at java.lang.Object.wait(Native Method) 
     - waiting on <0x0ad4f1f0> (a org.hsqldb.lib.HsqlTimer$TaskQueue) 
     at org.hsqldb.lib.HsqlTimer$TaskQueue.park(Unknown Source) 
     - locked <0x0ad4f1f0> (a org.hsqldb.lib.HsqlTimer$TaskQueue) 
     at org.hsqldb.lib.HsqlTimer.nextTask(Unknown Source) 
     - locked <0x0ad4f1f0> (a org.hsqldb.lib.HsqlTimer$TaskQueue) 
     at org.hsqldb.lib.HsqlTimer$TaskRunner.run(Unknown Source) 
     at java.lang.Thread.run(Unknown Source) 

"Grizzly-HttpSession-Expirer" daemon prio=6 tid=0x19fbc800 nid=0x27dc waiting on condition [0x1b27f000] 
    java.lang.Thread.State: TIMED_WAITING (parking) 
     at sun.misc.Unsafe.park(Native Method) 
     - parking to wait for <0x0a87eb58> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject) 
     at java.util.concurrent.locks.LockSupport.parkNanos(Unknown Source) 
     at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.awaitNanos(Unknown Source) 
     at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(Unknown Source) 
     at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(Unknown Source) 
     at java.util.concurrent.ThreadPoolExecutor.getTask(Unknown Source) 
     at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) 
     at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) 
     at java.lang.Thread.run(Unknown Source) 

"Service Thread" daemon prio=6 tid=0x00fc2c00 nid=0x21e0 runnable [0x00000000] 
    java.lang.Thread.State: RUNNABLE 

"C1 CompilerThread0" daemon prio=10 tid=0x00fab000 nid=0x12d0 waiting on condition [0x00000000] 
    java.lang.Thread.State: RUNNABLE 

"Attach Listener" daemon prio=10 tid=0x00fa9c00 nid=0x1ebc waiting on condition [0x00000000] 
    java.lang.Thread.State: RUNNABLE 

"Signal Dispatcher" daemon prio=10 tid=0x00fa6c00 nid=0x23e4 runnable [0x00000000] 
    java.lang.Thread.State: RUNNABLE 

"Finalizer" daemon prio=8 tid=0x00f76400 nid=0xe20 in Object.wait() [0x188af000] 
    java.lang.Thread.State: WAITING (on object monitor) 
     at java.lang.Object.wait(Native Method) 
     - waiting on <0x09ba5c80> (a java.lang.ref.ReferenceQueue$Lock) 
     at java.lang.ref.ReferenceQueue.remove(Unknown Source) 
     - locked <0x09ba5c80> (a java.lang.ref.ReferenceQueue$Lock) 
     at java.lang.ref.ReferenceQueue.remove(Unknown Source) 
     at java.lang.ref.Finalizer$FinalizerThread.run(Unknown Source) 

"Reference Handler" daemon prio=10 tid=0x00f71000 nid=0x20d8 in Object.wait() [0x186ef000] 
    java.lang.Thread.State: WAITING (on object monitor) 
     at java.lang.Object.wait(Native Method) 
     - waiting on <0x09ba5d08> (a java.lang.ref.Reference$Lock) 
     at java.lang.Object.wait(Object.java:503) 
     at java.lang.ref.Reference$ReferenceHandler.run(Unknown Source) 
     - locked <0x09ba5d08> (a java.lang.ref.Reference$Lock) 

"VM Thread" prio=10 tid=0x00f6fc00 nid=0x229c runnable 

"VM Periodic Task Thread" prio=10 tid=0x00fe7800 nid=0x2480 waiting on condition 

JNI global references: 204 

有趣的是,沒有列出的線程都從我自己的代碼,他們都似乎是從Java標準庫,除了HSQLDB和灰熊線程。我已經測試了幾個不同的JDK發行版,但似乎並不重要。

有誰知道我可能會做錯什麼或如何解決它?

感謝

+1

那些池線程看起來很可疑。你「關閉」了你的游泳池嗎? http://stackoverflow.com/questions/13883293/turning-an-executorservice-to-daemon-in-java – 2014-09-11 10:03:39

+0

我沒有在我的代碼中維護任何線程池,所以它必須來自其他地方(我是使用幾個第三方庫用於HTTP服務器和SSH連接)。你知道是否有辦法找出它的創建地點? – Petter 2014-09-11 10:35:07

回答

2

我發現這個問題,並會張貼在這裏如果有人有興趣。

應用程序與HSQLDB一起使用Hibernate,並且我創建了一個實用程序類來簡化對EntityManagerFactories的處理。它包含了這樣的方法:

private static javax.persistence.EntityManagerFactory getEntityManagerFactory() { 
    if (emf == null) { 
     Map properties = new HashMap(); 
     properties.put("hibernate.connection.url", "jdbc:hsqldb:file:" + 
       ConfigurationUtil.CONFIG_DIRECTORY + File.separator + 
       "local.db"); 
     emf = Persistence.createEntityManagerFactory("FPU", properties); 
    } 
    return emf; 
} 

實際情況是,在啓動多個線程調用此方法,引起了許多EntityManagerFactories的創建。這導致應用程序不能正確關閉。使上述方法​​解決了這個問題。