我有一个标准的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和Grizzly线程除外。我已经使用一些不同的JDK发行版进行了测试,但似乎并不重要。
有谁知道我可能做错了什么或如何解决它?
由于
答案 0 :(得分:2)
我发现了问题并将其发布在此处,以防有人感兴趣。
应用程序使用Hibernate和HSQLDB,我创建了一个实用程序类来简化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。这导致应用程序无法正常关闭。制作上述方法synchronized
解决了这个问题。