Reputation: 8762
Is there a way to know when a specific process is "stuck" in Java?
I'm running an external application from my java program. Sometimes, this app hangs. I would like to know when this app stops working so I can kill it from my code. I'm thinking of some type of monitoring from a different thread in my code.
Any toughts?
Upvotes: 1
Views: 3033
Reputation: 75386
Under java 6 you can get a thread dump for All threads. If you snapshot these every minute you Can see what goes ón.
Upvotes: 1
Reputation: 1554
If the other app is also java, you could use the Java Service Wrapper for monitoring and restarting it in the event that it is hung.
http://wrapper.tanukisoftware.org/doc/english/download.jsp
Upvotes: 0
Reputation: 83250
My first question would be to ask what you mean by "stuck". Is it in an infinite loop? Is it deadlock?
By the nature of the question I'm guessing you don't know, but if all you want to do is kill it when it hangs, you can have it write some output to a file periodically. Another process can monitor this file, and if some number of periods go by without seeing output, you can kill it then.
Upvotes: 0