Is it possible to access a JVM's JMX server from inside that JVM instance? Or would I have to connect through the standard socket/port remote interface?
+----------------------------------------+ Option 2: Connect
| +---------------------------+ | through sockets like
| | My Notification Listener |+----->----------+ a remote
| | | | | monitor.
| +---------------------------+ | |
| + | |
| Option 1: connect| | |
| to the internal | | |
| JMX server. I'm | | |
| trying to find | | |
| if this is possible. | |
| | | |
| | | |
| A single JVM instance. | | |
| | | |
| +------------+-----v------+--+ | |
| | | GuageMXBean|<-+<--------------+
| | +------------+ | |
| | JMX MXBean Server | |
| +----------------------------+ |
+----------------------------------------+
Context: I'm trying to implement an 'intelligent' system that responds to JVM state, specifically memory usage, shifting between caching working data to disk, and holding it in ram. Setting up a JMX listener seemed more elegant than running a background thread that does something like:
Runtime RTime = Runtime.getRuntime();
while(!shutdown)
{
if((RTime.totalMemory / RTime.maxMemory) > upperThreshold) cachmode = CACHETODISK;
if((RTime.totalMemory / RTime.maxMemory) < lowerThreshold) cachmode = CACHETORAM;
Sleep(1000);
}
Desktop application, if it makes a difference.
This is my first SO post, so any hints on improvement, etc. of the question are welcome.