Runtime class

 

前面谈到了用Process类调用外部程序的问题时,说到了Runtime,所以今天我就看一点相关的东西。

Every Java application has a single instance of class Runtime that allows the application to interface with the environment in which the application is running. The current runtime can be obtained from the getRuntime method.

An application cannot create its own instance of this class.

 

基本上可以使用这个类获得一些processer,memory相关的信息。

其他的应用是:

 

1, 执行一个新进程

比如执行外部程序时用的语句是:

Runtime.getRuntime().exec(command, getEnvp(), getWorkingFolder());

Executes the specified command and arguments in a separate process with the specified environment and working directory.

Given an array of strings cmdarray, representing the tokens of a command line, and an array of strings envp, representing "environment" variable settings, this method creates a new process in which to execute the specified command.

好多时候String[] evn不需要什么,传null就可以了。

 

2,ShutdownHook

还有一个addShutdownHook方法的使用,我在http://blog.csdn.net/onlyqi/article/details/6556748 中提到的。

static class ShutdownHook extends Thread

{

     public void run() { unlockFile();

}

ShutdownHook shutdownHook = new ShutdownHook();

Runtime.getRuntime().addShutdownHook(shutdownHook);

A shutdown hook is simply an initialized but unstarted thread.

When the virtual machine begins its shutdown sequence it will start all registered shutdown hooks in some unspecified order and let them run concurrently.

When all the hooks have finished it will then run all uninvoked finalizers if finalization-on-exit has been enabled.

Finally, the virtual machine will halt.

Note that daemon threads will continue to run during the shutdown sequence, as will non-daemon threads if shutdown was initiated by invoking the exit method.

 

3, trace 一些对象。目前不太懂。

4, Run finalization methods.

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值