Alex Rivera | Logout

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

Asked 2010-07-13T10:57:37.797
10

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() 
Edit
Report

2 Answers

0

Thread dumps and debuggers would be my guess.

answered 2010-07-13T10:59:30.587
0

Unsafe.park, despite the scary-sounding name, is typically used by all kinds of blocking calls (especially those in the new(ish) java.util.concurrent package).

If you look a few frames further down the stack, you'll like see something like java.util.concurrent.LinkedBlockingQueue.take (i.e. some JDK library class) followed by something like com.example.myapp.MyClass.getNextJob (i.e. your class that's using the library class).

If I had to hazard a guess, I'd say that you're making some kind of call that blocks forever - and so when there's nothing further to return, this thread just sits there waiting for the "next" item. You could resolve this by setting some kind of "finished" flag, and then either interrupting the waiting thread or giving the blocking call a timeout, getting it to check the flag. Depending on your code either of these or an alternative could be feasible, but hopefully this is enough to get you started.

Edit: after seeing the stacktrace, finnw is right that you need to shutdown your executor service.

answered 2010-07-13T11:07:30.783

Your Answer