import java.io.IOException;
public class API {
public static void main(String[] args) throws IOException {
//Runtime表示当前虚拟机的运行环境
//通过getRuntime()获取对象
//获取Runtime对象
Runtime r1 = Runtime.getRuntime();
//exit停止虚拟机
//r1.exit(0);
//获取cpu线程数
System.out.println(r1.availableProcessors());
//已经获取的总内存大小
System.out.println(Runtime.getRuntime().totalMemory()/1024/1024);
//可获取的最大内存
System.out.println(Runtime.getRuntime().maxMemory()/1024/1024);
//剩余内存大小
System.out.println(Runtime.getRuntime().freeMemory()/1024/1024);
}
}
Runtime对象不能通过new获得,Runtime类构造方法用private修饰,无法在类外调用,getRuntime()方法为静态方法,保证Runtime的对象唯一
//操作cmd命令
/*
-s:默认在一分钟之后关机
-s -t:指定时间关机,单位秒
-a:取消关机操作
-r:关机并重启
*/
//Runtime.getRuntime().exec("shutdown -a");