문제

I want to load a custom JMX Client into a JVM by wrapping the client in a javaagent package and query MBeans locally. My intent is that the JMX Client will periodically query the host application's MBeans or receive notifications. However, since the javaagent is loaded before the main jar (via premain), the host applications's MBeans are not yet available. How should I handle this "chicken before the egg" problem? Are threads appropriate for this? Or is there some other JMX mechanism that would be preferred? Thank you

도움이 되었습니까?

해결책

Start a loop with a sleep in it until you successfully get the target MBeanServer. If this is the platform MBeanServer, you should get it immediately using ManagementFactory.getPlatformMBeanServer(). Then register a notification listener with the ObjectName defined as MBeanServerDelegate.DELEGATE_NAME. Filter for notifications of the class MBeanServerNotification, with notification types of MBeanServerNotification.REGISTRATION_NOTIFICATION. Your notification listener will get a callback every time a new MBean is registered in the target MBeanServer.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top