Блог пользователя Sanzee

Автор Sanzee, 13 лет назад, По-английски
we  are working on a educational OJ .We are facing difficulty finding total memory used by a java code in Linux (CenOS). As Linux process table shows the sum of the JVM memory and the code memory.How can I find the specific memory used by a java code ??????
please help.



  • Проголосовать: нравится
  • 0
  • Проголосовать: не нравится

13 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится
You can run this code inside JVM:
// Get current size of heap in bytes
long heapSize = Runtime.getRuntime().totalMemory();

// Get maximum size of heap in bytes. The heap cannot grow beyond this size.
// Any attempt will result in an OutOfMemoryException.
long heapMaxSize = Runtime.getRuntime().maxMemory();

// Get amount of free memory within the heap in bytes. This size will increase
// after garbage collection and decrease as new objects are created.
long heapFreeSize = Runtime.getRuntime().freeMemory();

13 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится
There is JMX - technology for monitoring and management Java-applications.
13 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится
thanks !!