Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where do I start investigating my Java process that won't end?

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() 
like image 867
JenFallow Avatar asked Jul 13 '10 10:07

JenFallow


1 Answers

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.)
like image 113
finnw Avatar answered Nov 15 '22 21:11

finnw