gcwatch is a simple JVM TI agent that monitors stop-the-world garbage collections and makes them available via a simple TCP server interface. This allows detecting if the machine and Java process is still running, even while the normal Java socket operations are blocked by the garbage collection event.
The server returns either
GC xxx where
xxx is the number of
milliseconds since the garbage collection began, followed by a newline.
Run Java with the agent added as a JVM argument, specifying the port number for the agent to listen on:
Alternatively, if modifying the Java command line is not possible, the
above may be added to the
JAVA_TOOL_OPTIONS environment variable.