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

-------------Problems Reply------------

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.)

Thread dumps and debuggers would be my guess.

Not sure how large the application is but I would check all the Threads you've created and ensure that their run methods are cleanly exited when the application is done executing. Somewhere, within a thread, you may have code along the lines of:

public void run() {
while(true) { //"true" or some condition that never gets a chance to be false
//do thread related work

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.

Your task is blocked waiting for data from the queue. Take doesn't have a timeout associated with it.

Maintain a reference to your task thread when it is created. At shutdown, call the interrupt method on the thread. You may also need to modify the work processing loop that calls take to exit when InterruptedException is caught.

Category:java Views:1 Time:2010-07-13

Related post

  • What is the default properties that eclipse uses to launch a java process in its debugging mode? 2010-04-16

    I would like to connect to java process started by eclipse using a command line debugger but not sure what default properties of the eclipse launched java process are ? I wouldn't mind using attaching using sockets but not sure how much slower that w

  • Why is this Java process failing to terminate? 2011-11-08

    I have an intermittent problem on a build server where a Java process in the build somehow fails to terminate and seems to continue running (using 100% of the CPU) forever (I've seen it run for 2+ days over the weekend where it normally takes about 1

  • How to stop java process gracefully? 2008-10-10

    How to stop java process gracefully in Linux and Windows? When does Runtime.getRuntime().addShutdownHook gets called, and when it does not? What about finalizers, do they help here? Can I send some sort of signal to java process from shell? I am look

  • Good Java Process Control Library 2008-10-10

    Java process control is notoriously bad - primarily due to inadequate support by the Java VM/JDK classes (e.g. java.lang.Process). I am wondering, are there any good open source libraries out there that are reliable. The requirements would be: OSS St

  • Running Selenium from a Java process 2008-11-26

    How would you run the Selenium process (thread) from a Java process so I don't have to start Selenium by hand? --------------Solutions------------- The server: import org.openqa.selenium.server.SeleniumServer; public class SeleniumServerControl { pri

  • How can a Java process with -Xmx1024m occupy 3GB resident memory? 2009-03-26

    It's a Java web application on Websphere6.1, Solaris 10, JDK 1.5.0_13. We set the maximum heap size to 1024m. jmap shows the heap status is healthy. The heap memory usage is only 57%. No OutOfMemory at all. But we saw very high RSS (3GB) for this jav

  • What is the best way to monitor (java) process deaths on a Windows box? 2009-03-27

    We have a curious problem with our java processes dying. The application doesn't stacktrace, or write anything to the logs, the process just randomly dies. It's a heavily used application, but the problem only appears about once a month. We're curren

  • Max amount of memory per java process in Windows? 2009-06-12

    What is the maximum heap size that you can allocate on 32-bit Windows for a Java process using -Xmx? I'm asking because I want to use the ETOPO1 data in OpenMap and the raw binary float file is about 910Mb. --------------Solutions------------- There'

  • How do I invoke a Java process from Windows Powershell? 2009-07-01

    I am having trouble running a Java program with Windows Powershell 2.0. Any help on this would be greatly appreciated. I want the string "Hello World!" to print to the main Powershell console window. Instead, its getting printed to a separate process

  • Access Other Java Processes 2009-08-20

    I am writing a program that starts another java process which runs certain code. Is there any way I can "talk" to that process to call methods of the running class(es)? --------------Solutions------------- You're going to have to use some form of rem

  • Gracefuly stop .net initiated Java Process 2009-10-01

    Having the next .net code, I want to stop it correctly so that the jvm executes it's ShutdownHooks. System.Diagnostics.Process p = new Process(); p.StartInfo.UseShellExecute = false; p.StartInfo.RedirectStandardError = true; p.StartInfo.RedirectStand

  • How do I specify a file to pass to a java process run by an Ant task? 2009-10-21

    I have an Ant task to call a java process that takes a file on the command line. I can pass the file directly to the java program but I can't figure out how to make Ant take the file on the command line. Here's what I've got: <target name="FilePro

  • Is it possible to programmatically close a Java process through JMX 2009-10-28

    I'm currently writing an app to monitor another Java process and take specific actions when certain targets are hit. For example, if a thread deadlocks for a certain time, kill the thread, if the memory usage goes over a specific amount, send email a

  • How to get the list of java processes along with their PID(process id) that are running on UAT server under a specfic account? 2009-11-14

    Problem: A jar file was failed to deploy on a UAT server. Reason: Because when we are trying to rename it,it is showing "cannot rename the file it is been used by another user". step choosen in order to solve the problem log on UAT server(xxx). we ne

  • How to pass sockets created to another Java Process 2009-12-17

    We have an application which creates many sockets which belongs to its thread, By design if this application somehow fails, all threads stop which is not wanted. So to overcome this issue, each thread must be separated from the main application, if o

  • How to get the number of threads in a Java process 2009-12-17

    How can I see the number of threads in a Java process? --------------Solutions------------- Useful tool for debugging java programs, it gives the number of threads and other relevant info on them: jconsole <process-id> java.lang.Thread.activeCo

  • Catch when java process has been terminated 2010-01-11

    How can I catch when somebody kills my application (java, but it is not important) by taskmanager or by taskkill console command? I understand that I cannot catch this IN my application but maybe I can do this by some hook with OS (windows of course)

  • Best Tool to collect Java process statistics and Explanation of JMAP 2010-01-18

    I am looking at collecting more detailed java statistics (in plain text format) i.e. statistics that the jstat command emits - like garbage collection data etc. Can anyone please suggest me the best tool to collect the java process statistics like jm

  • Background java process not exiting 2010-01-20

    I'm starting a java program in background with java what.ever.Class &. It throws an exception in the first line and prints out the stack. I'd expect the java process to exit at that point, but for some reason it stays there waiting (no code runni

Copyright (C) dskims.com, All Rights Reserved.

processed in 0.174 (s). 11 q(s)