DestroyJavaVM线程始终在运行 [英] DestroyJavaVM thread ALWAYS running

查看:5668
本文介绍了DestroyJavaVM线程始终在运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在分析我的应用程序时,我遇到了一个奇怪的行为 - DestroyJavaVM线程总是在运行 - 100%的时间。

When profiling my application I came across a weird behavior - the DestroyJavaVM thread is ALWAYS running - 100% of the time.


在对该主题进行一些研究之后,在网上几乎没有任何有价值的信息,我所理解的是这个帖子应该是退出时卸载JVM

如果是这种情况,为什么这个线程在100%的时间处于RUNNING状态我开始申请的第一时间?它是否消耗了宝贵的资源,因此可能导致 OutOfMemoryError (就像我有时会得到的那样)?

If that's the case, why is this thread in RUNNING state 100% of the time from the very first moment I start my application? Doesn't it consume valuable resources and therefore may cause an OutOfMemoryError (like I sometimes get)?

是否存在这个线程实际上做了什么以及什么触发了它的初始化的官方参考?

Is there any official reference to what this thread actually does and what triggers its initialization?

谢谢

推荐答案

这是因为大多数应用程序都在线程中运行。

This happens because most applications are run in threads.

所有 POJO 应用程序首先调用 main 方法。在最简单的情况下,此方法将完成所有工作,创建对象,调用方法等。一旦 main 完成,JVM将被告知使用<$ c关闭$ c> DestroyJavaVM 线程,它等待所有非守护进程线程在完成它之前完成。这是为了确保您创建的任何非守护程序线程在JVM拆除之前运行完成。

All POJO apps start by invoking the main method. In it's most simple case this method will do all of the work, creating objects, calling methods etc. Once main completes, the JVM is told to shut down using a DestroyJavaVM thread which waits for all non-daemon threads to complete before doing it's work. This is to ensure that any non-daemon threads you create run to completion before the JVM is torn down.

具有GUI的应用程序通常以数字形式运行线程。一个用于监视系统事件,如键盘或鼠标事件。一个用于维护窗口和显示等。这种应用程序的 main 方法可能只是启动所有必需的线程并退出。它仍然会创建 DestroyJavaVM 线程,但现在所做的就是在拆除虚拟机之前等待所有创建的线程完成。

An app with a GUI, however, normally runs as a number of threads. One for watching for system events such as keyboard or mouse events. One for maintaining the windows and display etc. The main method of this kind of app will probably just start up all the required threads and exit. It still creates the DestroyJavaVM thread but now all that does is wait for all of your created threads to finish before tearing down the VM.

因此,任何创建线程并完全依赖于其功能的应用程序都会有一个 DestroyJavaVM 线程等待它完成。由于它所做的只是加入所有其他正在运行的线程,它不会消耗任何资源。

As a result, any app that creates threads and relies solely on their functionality will allways have a DestroyJavaVM thread waiting for it to finish. Since all it is doing is joining all other running threads it does not consume any resources.

这篇关于DestroyJavaVM线程始终在运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆