• Post Reply Bookmark Topic Watch Topic
  • New Topic

Heap size in Java  RSS feed

 
PN Kumar
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How do i find the Heap size of the server through Java
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Heap size" is a property of a process, not of a machine. I'm not sure whether you're asking how to get the total memory available to a Java process, or how to find out the total memory available on a machine. The answer to the first question is the method Runtime.maxMemory(); "Runtime.getRuntime().maxMemory()" is the maximum number of bytes available for the Java heap. As far as the Java program is concerned, that's all the memory available on the machine.
If you're asking how to really find out the physical RAM size on the host computer: there's no way to do this built into Java, and of course there's no OS-independent way to do it outside of Java, either. If you only need to do this on a particular OS, you could, for example, use Runtime.exec() to run some system utility that reported this value.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!