Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between a standard MBean and dynamic MBean?

Tags:

java

jmx

mbeans

What is the different between:

  1. Standard MBeans
  2. Dynamic MBeans

What are the pros and cons of each and when should we choose either of these two components to manage a resource?

like image 276
Geek Avatar asked Apr 25 '13 12:04

Geek


1 Answers

A standard mbean has fixed meta-data which does not change during the lifetime of the MBean. Dynamic MBeans define their meta-data on the fly and can modify and re-publish their meta-data. Think about this [badly] contrived analogy to Java: Let's say you wrote a class that listed the number of files in a directory. A standard class method might look like:

public int getFileCount(String directoryName)

On the other hand, the Dynamic MBean version of this class would start with no methods, but when it starts up, it scans the directories available, and creates a new method for each directory found:

public int getFileCountDir1();
public int getFileCountDir2();
....
public int getFileCountDirN();

So that's not a very useful setup, but suppose you wanted to create an MBean that displayed all the JVM's System Properties. Well.... System Properties change... and there's no reasonable way of knowing which property keys will be defined ahead of time, so that would be a better representation of what a Dynamic MBean is good for.

The pros and the cons really come down to:

  1. Standard MBeans are easy to create, and existing class instances can be wrapped and exposed as standard mbeans.
  2. Dynamic MBeans are cool when they serve a useful purpose, but they are measurably more effort to implement.
like image 186
Nicholas Avatar answered Sep 30 '22 10:09

Nicholas