java实现看门狗_Java看门狗监控

可以 '信号' 通过写/从程序INT/OutputStream中

读好一个过程,落实德线(见下文)

我不知道.. 。

也许这个片段有助于

public class ProcessTest {

public static void main(String[] args) {

new ProcessTest().start();

}

private void start() {

startWatchDog();

startProcess();

}

private boolean abortCondition = false;

private int watchDogTSleepTime = 3000; //3 sek

private void startWatchDog() {

Runnable r = new Runnable() {

@Override

public void run() {

while(!abortCondition){

try {

Thread.sleep(watchDogTSleepTime);

} catch (InterruptedException e) {

e.printStackTrace();

}

//check the file touch

boolean ok = checkFileTouch();

try {

//send signals to the process

outStream.write("signal".getBytes());

} catch (IOException e) {

e.printStackTrace();

}

//if you want, you might try to kill the process

process.destroy();

}

}

};

Thread watchDog = new Thread(r);

watchDog.start();

//watchDog.setDaemon(true); //maybe

}

private boolean checkFileTouch(){

//...

return false;

}

private InputStream inStream;

private OutputStream outStream;

private Process process;

private void startProcess() {

String[] cmd = new String[]{"foo.exe", "para1", "param2"};

try {

//create and start the process

process = Runtime.getRuntime().exec(cmd);

inStream = process.getInputStream();

outStream = process.getOutputStream();

} catch (IOException e) {

e.printStackTrace();

}

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值