-1

When I set Xmx value,I found heap init value is 0 through Java API, I set Xms and Xmx values ,I found heap init value is not 0 through Java API, I not set Xms and Xmx values ,I found heap init value is not 0 through Java API.

  1. -Xmx512M
  2. -Xms256M -Xmx512M
  3. not set

I found that JDK1.5 would have this problem. MemoryUsage heapMemoryUsage = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage(); heapMemoryUsage.getInit();

I want to know the principle

Immortal
  • 1
  • 2
  • Your question is extremely hard to understand. The English is bad but that's acceptable, however the question seems insensible, assuming that I'm reading it correctly. From what I am gather about the question, the value you are setting via "Xmx"(max heap size) is "0" , – Wayne Dec 06 '17 at 06:44
  • @Immortal - could you paste your command line arguments here? – James Lim Dec 06 '17 at 06:48

1 Answers1

1

Trying my best to interpret: -Xms lets you set the minimum heap size. This is what the JVM starts with. As your process requires more memory, it requests memory from the OS. -Xmx lets you set the max heap size; if your process exceeds the value you set for -Xmx, it throws a java.lang.OutOfMemoryError.

Perhaps, this is what you need: How's the default java heap size determined?

James Lim
  • 12,332
  • 3
  • 37
  • 63
  • "max heap size and, by extension, max memory" just a suggestion, since you mentioned the memory anyway. Will delete this comment if you want. – Wayne Dec 06 '17 at 06:48
  • I would leave your comment there for posterity: memory in Java is heap and stack, and `-Xmx` doesn't cap stack. – James Lim Dec 06 '17 at 06:50
  • Could you possibly post a (couple) link(s) in regards to that statement? I'm not calling you a liar, but I'm curious because I could have swore that Xms/Xmx were related to heap/stack depth, as opposed to being directly related to the memory. I would actually enjoy reading up on this tbh, the more you know. – Wayne Dec 06 '17 at 06:55
  • Thank you very much for answering my question, and I recount the question. Can you understand it? What you are answering now is not what I want – Immortal Dec 06 '17 at 07:54
  • @Immortal, I personally believe that it may have something to do with the bean. I'll admit that it's fully possible that this is an incorrect statement, though as I can't say for certain. However, at this time, I would like to suggest that you try using functions within `Runtime.getRuntime()` to calculate the available/used/total memory values, to see if the result comes out the same. I use Java version 8/9, I've never used 1.5, even on linux 1.6 was the earliest version I recall working with. – Wayne Dec 06 '17 at 08:41