Can't debug javax.management.NotificationListener code

Answered

In my application I monitor memory usage with java.lang.management.MemoryMXBean and java.lang.management.MemoryPoolMXBean (similarly to http://www.javaspecialists.co.za/archive/newsletter.do?issue=092&locale=en_US).

I set javax.management.NotificationListener to MemoryMXBean - to be informed when memory usage exceeds a threshold limit. The problem is when this listener invokes a method having some breakpoints inside - neither of them ever works for me, i.e debugger never stops on any of them. So I can't debug NotificationListener code ..

2
7 comments
Avatar
Permanently deleted user

Have you found any way to debug NotificationListener classes?

0

I think it is difficult to do, because NotificationListener is implemented by  JVM underlying Java code through JNI. I guess it bypasses JDI. It is really a challenging problem.

0

Hi,

I've debug the IDEA community source code com.intellij.openapi.util.LowMemoryWatcherManager and it's just stoped at a breakpoint:

Could you provide a sample project for this?

0

Sure, I just have a simple Spring Boot Application like this, I want to break at System.out.println("hello world");,however I couldn't.

public class DemoApplication {
    public static void main(String[] args) {
        List<GarbageCollectorMXBean> gcBeans = ManagementFactory.getGarbageCollectorMXBeans();
        for (GarbageCollectorMXBean gcBean : gcBeans) {
            NotificationEmitter emitter = (NotificationEmitter) gcBean;
            NotificationListener listener = new NotificationListener() {

                @Override
                public void handleNotification(Notification notification, Object handback) {
                    System.out.println("hello world");
                }
            };
            emitter.addNotificationListener(listener, new NotificationFilter() {

                @Override
                public boolean isNotificationEnabled(Notification notification) {
                    return true;
                }
            }, null);
        }
        SpringApplication.run(DemoApplication.class, args);
    }
}
0

Did you tried to limit your application's run memory? It should be set to a very low memory to enable the trigger. Also did you run it using maven/gradle runner or the IDEA one? I can debug it normally.

 

0

I can indeed debug in JDK17. Unfortunately it does not work in JDK8. I am using azul version 1.8.0_412:

0
It seems it doesn't work with JDK 8 or JDK 11, so it's possible that a JDK bug, IDEA, relies on JDK to debug them. Please use JDK 17+ as a workaround.
0

Please sign in to leave a comment.