A Java Agent that shuts down after installed. The agent should be installed dynamically with Sun Attach API. Here is an example, how:
VirtualMachine vm = VirtualMachine.attach(pid);
vm.loadAgent(pathToShutdownAgentJar, args);
Three arguments are supported:
- exitcode: The exit code that the agent should use to stop the JVM. The code is used when everything went well; all shutdown hooks ran and there are only daemon threads left. The default value is 0.
- timeout: The agent waits until the timeout, before shuts down the JVM forcibly by calling Runtime.halt(haltcode). The value is specified in milliseconds. If the value is less than or equal to 0, the agent will wait forever for a clean shutdown. The default value is 0.
- haltcode: The code that the agent uses during stopping the JVM forcibly after the timeout. Default value is 1.
Arguments should be separated by comma. E.g.:
vm.loadAgent(pathToShutdownAgentJar, "timeout=1000,haltcode=5");
The artifact is available on maven-central.