Java Runtime.maxMemory incorrect?

后端 未结 4 1859
北荒
北荒 2020-12-07 00:02

I ran the following method Runtime.getRuntime().maxMemory() and gave 85196800.

However, I then ran top from the command line and it showed

  PID U         


        
4条回答
  •  独厮守ぢ
    2020-12-07 00:49

    The Javadocs for that method are wrong, or at least very misleading. This Sun bug report explains.

    The other point is that the 156Mb shown as RES is the current "resident set" size; i.e. the amount of physical RAM currently attributed to the application. This number is liable to increase and decrease depending on the virtual memory demands of the system services / daemons and applications running on the machine. The numbers that the JVM purports to report are the JVM's virtual memory allocation.

    Suffice it to say that this is all as clear as mud, and probably not worth your effort to try to figure it out. If you really care, pay attention to what top, vmstat and so on tell you, and ignore the JVM numbers.

提交回复
热议问题