Obtaining memory available to JVM at runtime

前端 未结 4 1845
北恋
北恋 2020-12-21 10:01

I\'m trying to sort a bunch of data such that that the size of data input to the program can be larger than the memory available to the JVM, and handling that requires exter

4条回答
  •  情歌与酒
    2020-12-21 10:49

    You can use the Runtime class to get the amount of memory available.

    Runtime r = Runtime.getRuntime();
    System.out.println(r.totalMemory());
    

    There are various other memory details you can get from the Runtime object - see Runtime class.

提交回复
热议问题