如何查看java程序使用了多少资源?
如何查看java程序使用了多少资源?
在java中,创建一个大而好的程序非常容易,它几乎可以完成您想要它做的所有事情,但有一点副作用是,也很容易错误地间接分配大量内存和CPU周期(即,让我们只使用“new “几次在错误的地方)。
如果程序应该在资源非常有限的环境中运行,比如说嵌入式设备或者手机(J2ME、Android 等), 了解您的程序对资源的需求程度至关重要。
注意:由于过去几年我的主要关注点是 c,所以我可能会在这里遗漏一些非常简单的东西,所以请不要假设太多;)
谢谢 约翰
How do I check how much resources a java program uses?
In java it is quite easy to create a big nice program that does practically everything you want it to, but a little side effect is that is also very easy to indirectly allocate to much memory and cpu cycles by mistake (i.e. let's just use "new" a couple of times in the wrong place).
And if the program are supposed to run in a environment with very limited amount of resources, let's say something embedded or maybe a mobile phone (J2ME, Android etc etc),
it is crucial to know how resource hungry your program is.
Note: Since my main focus has been c the last years I could be missing something very simple here, so please don't assume to much ;)
Thanks
Johan
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您似乎对自己真正需要的东西有些困惑。 在你的问题中,我感觉到了一些不安:“Java会在我背后吞噬多少资源来咬我?”。
用道格拉斯·亚当斯的话来说,答案是:“不要惊慌!” :-)。
说真的,Java 不一定比“本机”应用程序使用更多的资源,因此您可能不必担心。
快速概述:
简短版本:别担心,只需像往常一样操作即可:使其运行、使其正确运行、使其快速运行(通过分析)。
You appear to be somewhat confused about what you really need. In your question I sense some uneasiness about "how many resources will Java gobbly up behind my back to bite me later?".
The answer to this is, to paraphrase Douglas Adams: "Dont' panic!" :-).
Seriously, Java does not necessarily use much more resources than a "native" application, so you probably need not worry.
A quick rundown:
Short version: Don't worry, just do as you always do: Make it run, make it run correctly, make it run fast (by profiling).
如果您试图在程序之外捕获这些属性以进行性能测试; 您可能还想使用 Java Profiler。 那里有很好的分析器可用。 Java 6 还提供了一种方法来执行此类活动。
例如
J 分析器
如果你想要更多这样的工具; 让我知道。
if you are trying to capture these attributes outside the program for performance tests; you might also wanna use Java Profilers. There are good profilers available out there. Java 6 also provides one to do these kinds of activities.
for example
J Profiler
If you want more such tools; let me know.
从 Java 1.6 开始,出现了一组允许监视 JVM 的工具。 其中之一是 jmap。 你可以看一下。
我不太确定它如何应用于 J2ME,但我猜您可以将相同的技术应用于计算机上的 J2ME 模拟器(使用完整的 JVM,而不是 KVM)。
Since Java 1.6 there's a set of tools allowing to monitor the JVM. One of them is jmap. You could take a look at it.
I am not quite sure how it applies to J2ME, but I would guess you could apply the same technique to the J2ME emulator on a computer (using full JVM, not a KVM).