DestroyJavaVM thread ALWAYS works

When profiling my application, I came across strange behavior - the DestroyJavaVM thread ALWAYS works - 100% of the time.

enter image description here Having done a little research on this issue, on which there is practically no valuable information on the Internet, I realized that this thread should unload the JVM after the release .

If so, why is this thread in RUNNING 100% of the time since the very first moment I start my application? Doesn’t it consume valuable resources and therefore can cause OutOfMemoryError (for example, I sometimes get it)?

Is there any official link to what this thread really does and what causes it to initialize?

thanks

+6
source share
1 answer

This is because most applications run in threads.

All POJO applications begin by calling the main method. In this simplest case, this method will do all the work by creating objects, calling methods, etc. Upon completion, the main JVM will close using the DestroyJavaVM thread, which waits for all non-daemon threads to complete before doing so. This is to ensure that all threads you create are executed before the JVM completes.

A GUI application, however, usually works as multiple threads. One for viewing system events, such as keyboard or mouse events. One to support windows and display, etc. The main method of this type of application will probably just start all the necessary threads and exit. It still creates the DestroyJavaVM thread, but now all it does is wait for all of your created threads to complete before the VM breaks.

As a result, any application that creates threads and relies solely on their functionality will always have a DestroyJavaVM thread waiting for its completion. Since all he does is join for all other running threads, he does not consume any resources.

+31
source

All Articles