RunTime(java)

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");

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值