Runtime 类只拥有私有构造方法,通过单例模式 getRuntime() 方法初始化
Runtime runtime = Runtime.getRuntime();
执行本机程序
//通过exec() 方法执行本机程序,需抛出异常, exec()方法返回一个Process类的实例,表示一个进程的对象
Process process = runtime.exec("notepad");
//关闭本机程序
process.destroy();
使用Runtime取得系统信息,显示最大可用内存 Runtime.getRuntime().maxMemory() ,空闲内存空间 Runtime.getRuntime().freeMemory() ,总共内存空间 Runtime.getRuntime().totalMemory() 等信息
使用 Runtime.getRuntime().gc()方法强制释放垃圾信息
取得系统当前时间
System.currentTimeMillis();
垃圾回收
对象被创建之后,如果不被引用,被不定期被垃圾处理机构回收,如果需要强制回收某不被引用的对象,需调用 System.gc() 方法(等价于调用了 Runtime.getRuntime().gc() 方法),完成之后会自动调用Object类中的 finalize() 方法,可以利用此方法进行收尾工作。