简体   繁体   English

获取线程的内存使用情况

[英]Get memory usage of a thread

I know that I Java's Runtime object can report the JVM's memory usage. 我知道我的Java 运行时对象可以报告JVM的内存使用情况。 However, I need the memory usage for a certain thread. 但是,我需要某个线程的内存使用情况。 Any idea how to get this? 任何想法如何得到这个?

I appreciate your answer! 感谢您的回答!

A Thread shares everything except its stack and the CPU cycles with all other threads in the VM. 线程与VM中的所有其他线程共享除堆栈和CPU周期以外的所有内容。 All objects created by the Thread are pooled with all the other objects. 线程创建的所有对象都与所有其他对象合并在一起。

The problem is to define what the memory usage of a Thread is. 问题是要定义线程的内存使用量。 Is it only those objects it created? 仅仅是它创建的那些对象吗? What if these objects subsequently are referenced by other threads? 如果这些对象随后被其他线程引用怎么办? Do they only count half, then? 那他们只算一半吗? What about objects created somewhere else, but are now referenced by this Thread? 那么在其他地方创建但现在被该线程引用的对象呢?

I know of no tool trying to measure the memory consumption of separate Threads. 我知道没有工具尝试测量单独线程的内存消耗。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM