Eclipse中設定JVM記憶體方法
阿新 • • 發佈:2019-02-06
public class TestMemory {
/**
* @param args
*/
public static void main(String[] args) {
System. out .println( " 記憶體資訊 :" + toMemoryInfo ());
}
/**
* 獲取當前 jvm 的記憶體資訊
*
* @return
*/
public static String toMemoryInfo() {
Runtime currRuntime = Runtime.getRuntime ();
int nFreeMemory = ( int ) (currRuntime.freeMemory() / 1024 / 1024);
int nTotalMemory = ( int ) (currRuntime.totalMemory() / 1024 / 1024);
return nFreeMemory + "M/" + nTotalMemory + "M(free/total)" ;
}
}
/**
* @param args
*/
public static void main(String[] args) {
System. out .println( " 記憶體資訊 :" + toMemoryInfo ());
}
/**
* 獲取當前 jvm 的記憶體資訊
*
* @return
*/
public static String toMemoryInfo() {
Runtime currRuntime = Runtime.getRuntime ();
int nFreeMemory = ( int ) (currRuntime.freeMemory() / 1024 / 1024);
int nTotalMemory = ( int ) (currRuntime.totalMemory() / 1024 / 1024);
return nFreeMemory + "M/" + nTotalMemory + "M(free/total)" ;
}
}