Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to programmatically close a Java process through JMX

Tags:

java

jmx

I'm currently writing an app to monitor another Java process and take specific actions when certain targets are hit. For example, if a thread deadlocks for a certain time, kill the thread, if the memory usage goes over a specific amount, send email alerts and kill the process, etc.

My app will run as a stand-alone app, monitoring specific other apps (locally, though from what I can see remote or local makes no difference here).

I'm monitoring the external JVMs via MXBeans, but cannot see a clean way to kill the external process short of a system call like 'kill -9 ' (I'm working in UNIX by the way).

Is there any way to kill a JVM through the MXBean interfaces?

Graham

like image 310
GKelly Avatar asked Oct 28 '09 10:10

GKelly


People also ask

How do you stop a Java application gracefully?

In your application implement a shutdown hook. When you want to shut down your JVM gracefully, install a Java Agent that calls System. exit() using the Attach API.

How does JMX work in Java?

Benefits of JMX Technology Manages Java applications and services without heavy investment: JMX architecture relies on a core managed object server that acts as a management agent and can run on most Java-enabled devices. Java applications can be managed with little impact on their design.

Why you would want to use a JMX monitoring tool?

JMX Monitoring to Improve the Performance of Java Applications. Easily monitor JVMs and Java web application servers with the eG Enterprise JMX monitoring solution. Improve the performance of your applications by identifying bottlenecks at the code-level and in the infrastructure.

What is JMX port used for?

The JMX technology can be used for out-of-the-box management of the Java VM. The Java Virtual Machine (Java VM) is highly instrumented using the JMX technology. You can start a JMX agent to access the built-in Java VM instrumentation, and thereby monitor and manage a Java VM remotely.


1 Answers

Sure. Implement an MBean on the target server that calls System.exit(), and invoke that as a JMX operation from the client.

like image 151
skaffman Avatar answered Nov 15 '22 22:11

skaffman