Java VisualVM如何显示未运行/未完成的线程? [英] How Java VisualVM shows threads that are not running/finished?

查看:419
本文介绍了Java VisualVM如何显示未运行/未完成的线程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为了进行测试,我创建了一个仅在其中休眠的线程.而且我知道即使使用完毕,GC也不会在一段时间内收集它们,但是当您在完成它们的任务后不将它们保留为对象时,它们应该消失了.

For testing I've created a thread which has just sleep in it. And I know that GC doesnt collect them for a while even if their usage is done but when you dont keep them as an object after they complete their task they should've be gone.

因此,出于测试目的,我使用了Java VisualVM,但这是我第一次使用它.而且我看到所有这些计时器线程都在0ms左右,但我仍然可以看到它们.这正常吗?那是什么意思呢?如果我向成千上万的垃圾邮件发送垃圾邮件,会降低我的应用程序速度吗?

So for testing purposes I used Java VisualVM but this is the first time I'm using it. And I see all these timer threads lying around with 0ms but I can still see them. Is this normal? And what does this mean? If I spam thousands of them, will it slow down my app?

推荐答案

一旦VisualVM连接到正在运行的JVM, it 就会保留对所有启动线程的引用,因此这些Thread对象不会被破坏线程停止运行时收集.

Once VisualVM connects to the running JVM, it will keep references to all started threads, so those Thread objects are not garbage collected when the threads stop running.

它们由VisualVM保留,因此您仍然可以查看为其收集的统计信息.

They are retained by VisualVM so you can still see the statistics collected for them.

一旦退出VisualVM,Thread对象将变得不可访问且可访问GC,因此停止和重新启动VisualVM将清除"已结束线程的列表.

The Thread objects will become unreachable and GC'able once you exit VisualVM, so stopping and restarting VisualVM will "clear" the list of ended threads.

这篇关于Java VisualVM如何显示未运行/未完成的线程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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