我在哪里开始调查我的Java进程不会结束? [英] Where do I start investigating my Java process that won't end?

查看:165
本文介绍了我在哪里开始调查我的Java进程不会结束?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个没有结束的Java应用程序。主要方法完成,但线程保持活动状态,应用程序不会结束。事情是,似乎没有任何监视器锁/等待,所以我看不到为什么它不结束。根据Eclipse,我留下了两个非守护进程线程。一个被标记为[DestroyJavaVM](看起来很有希望!),另一个被标记为 Unsafe.park(boolean,long)。如何/我应该在哪里开始调查?



第二个线程的简化堆栈跟踪是:

  Unsafe.park(boolean,long)
在LockSupport.park(Object)
在AbstractQueuedSynchronizer $ ConditionObject.await()
在LinkedBlockingQueue< E> .take )
在ThreadPoolExecutor.getTask()
在ThreadPoolExecutor $ Worker.run()
在Thread.run()


解决方案

您需要执行以下两项操作才能终止您的 ExecutorService 线程: / p>


  1. 指定一个

    a href =http://guava-libraries.googlecode.com/svn/trunk/javadoc/com/google/common/util/concurrent/ThreadFactoryBuilder.html =nofollow noreferrer> ThreadFactoryBuilder
    类来自 Guava 将使这更容易。)

  2. 致电 shutdown() 在您的 ExecutorService main 方法的末尾。)


I have a Java application which doesn't end. The main method finishes, but threads remain active and the application doesn't end. The thing is, there don't appear to be any monitor locks / waits, so I can't see why it's not ending. According to Eclipse, I am left with two non-Daemon threads. One is labelled [DestroyJavaVM] (looks hopeful!) and the other seems to be blocked in Unsafe.park(boolean, long). How / where should I start investigating this?

The abridged stacktrace of the second thread is:

   Unsafe.park(boolean, long)
at LockSupport.park(Object)
at AbstractQueuedSynchronizer$ConditionObject.await()
at LinkedBlockingQueue<E>.take()
at ThreadPoolExecutor.getTask()
at ThreadPoolExecutor$Worker.run()
at Thread.run() 

解决方案

You need to do one of two things to terminate your ExecutorService thread:

  1. Specify a ThreadFactory that creates daemon threads (the ThreadFactoryBuilder class from Guava will make this easier.)
  2. Call shutdown() on your ExecutorService as part of the application shutdown (e.g. at the end of your main method.)

这篇关于我在哪里开始调查我的Java进程不会结束?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆