本文介绍了我在哪里开始调查我的Java进程不会结束?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个没有结束的Java应用程序。主要方法完成,但线程保持活动状态,应用程序不会结束。事情是,似乎没有任何监视器锁/等待,所以我看不到为什么它不结束。根据Eclipse,我留下了两个非守护进程线程。一个被标记为[DestroyJavaVM](看起来很有希望!),另一个被标记为 a href =http://guava-libraries.googlecode.com/svn/trunk/javadoc/com/google/common/util/concurrent/ThreadFactoryBuilder.html =nofollow noreferrer> ThreadFactoryBuilder 类来自将使这更容易。)
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:
- Specify a ThreadFactory that creates daemon threads (the ThreadFactoryBuilder class from Guava will make this easier.)
- Call shutdown() on your ExecutorService as part of the application shutdown (e.g. at the end of your main method.)
这篇关于我在哪里开始调查我的Java进程不会结束?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!