【Java】Runtime类

Runtime类

Runtime类:
static Runtime getRuntime();
获取当前运行实例
int availableProcessors();
获取处理器个数
freeMemory();
获取空闲内存
maxMemory();
获取最大内存
Process exec(String dos);
执行dos命令

Process类:
void destroy();
结束当前进程
----------------------------------------------

public class Demo {
	public static void main(String[] args) throws IOException {
		
		//static Runtime getRuntime();
		Runtime rt = Runtime.getRuntime();
		System.out.println(rt);

		//int availableProcessors();
		int num = rt.availableProcessors();
		System.out.println("处理器个数是:" + num);

		//freeMemory();
		long memory = rt.freeMemory();
		System.out.println(Memory / 1024 /1024 + "MB");

		//maxMemory();
		long maxMemory = rt.maxMemory();
		System.out.println(maxMemory / 1024 /1024 + "MB");

		//Process exec(String dos);
		Pocess p = rt.exec("notepad.exe);

		//void destroy();
		p.destroy();
		
	}
}

运行结果:
java.lang.Runtime@15db9742
处理器个数是:8
60MB
885MB
发布了47 篇原创文章 · 获赞 4 · 访问量 1109

猜你喜欢

转载自blog.csdn.net/Hide111/article/details/105414477