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:
ThreadFactory
that creates daemon threads (the ThreadFactoryBuilder
class from Guava will make this easier.)shutdown()
on your ExecutorService
as part of the application shutdown (e.g. at the end of your main
method.)If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With