I’m writing a program which monitors Java Applications. I’d like to monitor the state of the native processes and know when they exit. This is fine; Java gives me the Process object and I can waitFor() on it.
However, the problem that arises is that if my program dies, I would like it to get the reference to the process back – which it can’t do in Java because it never created the process. My first guess was to send the process object over RMI and have the client app send it back when a reconnection occurs, but that won’t work because Process isn’t serializable.
I can think of a way to do this natively using JNA on Windows, but does anyone know if there is an existing library which will do this?
Cheers!
You can use WMI to implement this on Windows and command line utilities on Unix (if you need).
I know the following tools to work with WMI: JaWin, WIntegra, JInterop.
If your monitor is running in windows too you can use JaWin. It is a JNI wrapper over COM+ API. If you want to be cross platform and be able to monitor Windows machine from Unix machine use JInterop. It is open-source library that implements DCOM protocol in pure java. JIntegra is similar but commercial.
EDIT: probably even simpler solution. If you want to monitor java application just use JMX. Connect to this application using JMX either remotely or locally.
Good luck.