Download API_project/Runtime_module/src/Runtime_package/Runtime_demo1.java from zxy0307/Java: direct link, hf CLI and curl.
- Browser
- Download file 1.83 kB
-
https://huggingface.co/zxy0307/Java/resolve/main/API_project/Runtime_module/src/Runtime_package/Runtime_demo1.java
- Command line
-
hf download hf://zxy0307/Java/API_project/Runtime_module/src/Runtime_package/Runtime_demo1.java
-
curl -L -o Runtime_demo1.java https://huggingface.co/zxy0307/Java/resolve/main/API_project/Runtime_module/src/Runtime_package/Runtime_demo1.java
1.83 kB
| package Runtime_package; | |
| import java.io.IOException; | |
| public class Runtime_demo1 { | |
| public static void main(String[] args) throws IOException { | |
| /* | |
| 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剩余内存大小(单位byte) | |
| public Process exec(String command) 运行cmd命令 | |
| */ | |
| //1、获取Runtime的对象 | |
| Runtime r1 = Runtime.getRuntime(); | |
| Runtime r2 = Runtime.getRuntime(); | |
| System.out.println(r1 == r2);//true --- 只能获取一个Runtime对象 | |
| //2、exit 停止虚拟机 | |
| // r1.exit(0); | |
| // System.out.println("看看我执行了吗?"); | |
| //3、获取CPU的线程数 | |
| System.out.println(Runtime.getRuntime().availableProcessors()); | |
| //4、总内存大小 | |
| System.out.println(Runtime.getRuntime().maxMemory() / 1024 / 1024); | |
| //5、已经获取的总内存大小 | |
| 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:关机并重启 | |
| Runtime.getRuntime().exec("shutdown -a"); | |
| } | |
| } | |