java Runtime类
jvm进程运行类,可以通过该类获得进程信息
***********************
相关类
Runtime
public class Runtime {
private static final Runtime currentRuntime = new Runtime();
private static Version version;
public static Runtime getRuntime() {
return currentRuntime;
}
private Runtime() {}
************
常用方法
public Process exec(String command) throws IOException { //调用系统程序
public Process exec(String command, String[] envp) throws IOException {
public Process exec(String command, String[] envp, File dir)
public Process exec(String cmdarray[]) throws IOException {
public Process exec(String[] cmdarray, String[] envp) throws IOException {
public Process exec(String[] cmdarray, String[] envp, File dir)
public native long freeMemory(); //空闲内存
public native long totalMemory(); //总内存
public native long maxMemory(); //最大内存
public native void gc(); //通知虚拟机进行垃圾回收
public void exit(int status) { //jvm进程强制退出,0为正常退出,非0异常退出
public native int availableProcessors(); //可用处理器个数
***********************
示例
设置虚拟机参数:-Xmn10m -Xms20m -Xmx20m
package hello;
public class MyTest6 {
public static void main(String[] args){
Runtime runtime=Runtime.getRuntime();
System.out.println("可用处理器个数:"+runtime.availableProcessors());
System.out.println("空闲内存为:"+runtime.freeMemory()/(1024*1024)+"m");
System.out.println("最大内存为:"+runtime.maxMemory()/(1024*1024)+"m");
System.out.println("总内存为:"+runtime.totalMemory()/(1024*1024)+"m");
}
}
****************
控制台输出
可用处理器个数:8
空闲内存为:17m
最大内存为:20m
总内存为:20m