简体   繁体   English

在有限的资源环境中测试Java

[英]Testing Java for a limited resource environment

I'm writing java that will run in an environment with little memory. 我正在编写将在内存很少的环境中运行的Java。 My machine has loads of memory, so I need to limit the heap size (is this the only limit I can apply?). 我的机器上有很多内存,因此我需要限制堆大小(这是我可以应用的唯一限制吗?)。 I've been using "-Xmx100m" as a VM parameter in eclipse, but when I run the application I can see in the task manager that the memory used goes well above 100MB. 我一直使用“ -Xmx100m”作为eclipse中的VM参数,但是当我运行该应用程序时,我可以在任务管理器中看到所使用的内存远远超过100MB。 Am I using this incorrectly? 我使用不正确吗?

Also, most my memory is being allocated in local variables. 另外,我的大部分内存都在局部变量中分配。 These will be put on the thread's stack, which resides in the heap space, correct? 这些将被放在线程的堆栈中,该堆栈位于堆空间中,对吗? Just curious, what if my program was made entirely of static methods, where would these local variables be allocated? 很好奇,如果我的程序完全由静态方法组成,这些局部变量将分配在哪里呢?

Thanks! 谢谢!

edit: I suppose I should make my question simpler: How can I visualize an environment with less resources just for the jvm? 编辑:我想我应该使我的问题更简单:我如何可视化为jvm的资源较少的环境?

The stack always exists and variables can be allocated on it - regardless if it is a static method or not. 堆栈始终存在,并且可以在其上分配变量-不管它是否是静态方法。

I have also observed several times that jre actually uses more memory than specified with -Xmx setting. 我还观察到几次,jre实际上使用的内存多于-Xmx设置所指定的内存。 This is discussed in details in this question. 这个问题将详细讨论

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

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