What are some of the best practices in designing a JMX MBean? Any examples of ones you feel are especially useful?
The first thing that got me with my first JMX bean was return types - it's a lot easier if your methods return Strings - that way your client can easily display the response (I was mainly working with JConsole) - if you don't do this, you get things like com.mycompany.Response@xxxx as a response, which doesn't mean much :)
Return absolute counts instead of rates. e.g. return total number of db commits, rather than deriving a rate.
By doing this, your clients can monitor and derive rates themselves, over whatever time periods they require. Perhaps more importantly, this protects the clients from missing surges in rates if they only connect infrequently.
Make sure that attributes have no side effects and are predictable in operation.
There is nothing worse than an innocent looking attribute that executes a time-consuming (or resource-consuming) operation. I've seen some humdingers in my time..
Do not use JMX for logging so, for example, don't use an MBean function that returns details of all the connections since startup.
One should remember that JMX is meant for monitoring. Meaning - Display only data that is relevant to the current moment.