Process Watch Dog with Heartbeat Released!

It's nice to watch a process execution and kill frozen processes after timeout, but when a process is supplying data is not frozen even when it takes a long time.
Release 1.1.0 introduces a new process wrapper to send a heartbeat to reset the timeout explicitly or automatically with every read byte.


<dependency>
    <groupId>cz.net21.ttulka.exec</groupId>
    <artifactId>process-watch-dog</artifactId>
    <version>1.1.0</version>
</dependency>

Putting a process into watching returns a process wrapper:

Process process = ...

ProcessWatchDog watchDog = new ProcessWatchDog();

WatchedProcess watchedProcess = watchDog.watch(process, 1000);

Because the class WatchedProcess extends stadard Java class Process, we can do simply:

process = watchDog.watch(process, 1000);

Now, a heartbeat will be sent every time we read from the process input stream:

InputStream is = process.getInputStream();
int b;
while ((b = is.read()) != -1) {
    // heartbeat is sent implicitly with every successful call of `read()` 
}

To send a heartbeat explicitly, we can do it via the WatchedProcess object:

wp.heartBeat();

Or simply tell the Watch Dog to do it:

watchDog.heartBeat(process);   // we don't need the `WatchedProcess` object here

Previous post about the Watch Dog: Process Watch Dog Released!

All about: https://github.com/ttulka/process-watch-dog

Happy heartbeating!