常用API——Runtime

import java.io.IOException;

public class Test {
    public static void main(String[] args) {
        /*
        public static Runtime getRuntime()  表示当前系统的运行环江
        public void exit(int status)        停止虚拟机
        public int  availableProcessors()    获得CPU的线程总数
        public long maxMemory()     JVM能从系统中获取的总内存大小(单位是byte)
        public long totalMemory()   JVM已经从系统中获取的总内存大小(单位是byte)
        public long freeMemory()    JVM剩余内存大小
        public Process exec(String command)  运行cmd命令
         */


//        1.获取Runtime的对像
//        Runtime r1 = Runtime.getRuntime();

//        2.exit 停止虚拟机
//           Runtime.getRuntime().exit(0);

//         3.获取CPU线程总数
//        System.out.println(Runtime.getRuntime().availableProcessors());

//        4.获取内存总数
        System.out.println(Runtime.getRuntime().maxMemory()/1024/1024);

//        5。已经获取的总内存大小,单位byte
        System.out.println(Runtime.getRuntime().totalMemory()/1024/1024);

//        6.剩余内存大小
        System.out.println(Runtime.getRuntime().freeMemory()/1024/1024);

//        7.运行cmd命令;
//        shutdown : 关机
//        -s: 默认1分钟之后关机
//        -s -t 指定时间:指定关机时间
//        -a : 取消关机操作
//        -r : 关机并重启
        try {
            Runtime.getRuntime().exec("shutdown -a");
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

}

  • 4
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值