开发者

In Scala or Java, how to get how much RAM does application currently occupy?

开发者 https://www.devze.com 2023-01-14 06:23 出处:网络
NetBeans IDE has a taskbar indicaror, showing how much RAM is currently allocated and used by the running instance. How can I get this data in my own a开发者_高级运维pplication written in Scala? If th

NetBeans IDE has a taskbar indicaror, showing how much RAM is currently allocated and used by the running instance. How can I get this data in my own a开发者_高级运维pplication written in Scala? If there's no special function for this in Scala, I could use Java one.


private val runtime = Runtime.getRuntime()
import runtime.{ totalMemory, freeMemory, maxMemory }

 System.out.println("New session, \ 
    total memory = %s, max memory = %s, free memory = %s".format(
        totalMemory, maxMemory, freeMemory))

Just copied from http://harrah.github.com/browse/samples/compiler/scala/tools/nsc/CompileServer.scala.html


You can either use the totalMemory and maxMemory methods from the java.lang.Runtime class, or make use of the MemoryMXBean.

0

精彩评论

暂无评论...
验证码 换一张
取 消