mardi 15 juillet 2008

Killing a jvm thread running infinite loop in my app server simply using a Runtime Exception...

One frustrating thing in an application server (moreover in any jvm) is that you have no way to stop a thread going crazy : infinite loops, applicative deadlock...
With the ThreadMXBean API I can even auto detect such troubles logging easily the threads, their stacktraces (no more need for KILL -QUIT, yeahhh...), with ThreadLocal I can add data to get more information about the problem, but still I have no way to act on a thread and "stop it".

I would love to tell the jvm, ok, now the next code to execute on this thread is to raise a kind of RuntimeException... yes I want to say there is a trouble you can't recover from (anyway often it consumes all the cpu... horrible !), so a RuntimeException will correctly rollback all running transactions and correctly release resources. This would save me (and my team) from a server restart which is bad for our users...

Am I the only on to dream of that ? Is it impossible to provide this or nobody thought about it (couldn't find anything about this while googling...) ?

2 commentaires:

David Shay a dit…

Thread class has a deprecated stop method which can raise an exception in any thread. Can this help?

Nicolas FRANK a dit…

Not much... In a J2EE application server, I can't get a reference to a chosen thread and call a method on it... Moreover, I don't want to stop the thread (as it is managed by the application server), just make the current execution stack stop...