How to generate thread dumps when the JVM automatically terminates

Problem scenario: the problem is seen in the MF sound container (jvm). The container contains some java services responsible for operations with db and message conversions. After starting, the container works normally for 2-3 weeks and ends on its own, without any exceptions.

After much research, we cannot find out why or what caused the launch of jvm (MF Container).

Is there a way by which I can get the dumps of threads when jvm is automatically disconnected? I am using java 1.6. Is there any other approach to this problem I should follow?

Thanks in advance.

+2
java jvm
source share
2 answers

You can try java.lang.Runtime.addShutdownHook () and intercept the hook across all threads and unload their stack traces using Thread.getAllStackTraces () . However, if the JVM was stopped at Runtime.halt() , then interceptors will not be called. More complicated would be to use instrumentation to connect to the calls of Runtime.exit() and Runtime.halt() (or Shutdown.sequence() , see Edit # 2), so you can see exactly what is happening while you are cause.

EDIT . Another way to do this is to install a SecurityManager that does not provide any protection, but which downloads a list of threads whenever SecurityManager.checkExit() is called, since both the halt() and exit() methods call this security manager method. This would be much simpler than using tools, and you would even decide to throw an exception in addition to registering what the threads are doing.

EDIT 2 . The JVM system is working, it can say that the JVM will end, and in this case, using the Security Manager will not work. Also, the hardware on Runtime.exit() or Runtime.halt() will not be used, since the method that is called is java.lang.Shutdown.exit() . And if the JVM shuts down because the last daemon thread has completed, then Shutdown.shutdown() called. But buttons work in any of these situations. . Therefore, you should always use shutdown hooks, even if you are also going to use a security manager or toolkit.

+4
source share

See also https://docs.oracle.com/javase/7/docs/webnotes/tsg/TSG-VM/html/hangloop.html Troubleshooting Hanging or Loop Processes

However, at least in my case, Eclipse hangs and does not respond to any of them.

0
source share

All Articles