changeset 1397:1914e1156798

7901868: "gc" profiler should account for asynchronicity in GC notifications
author shade
date Thu, 15 Dec 2016 17:50:31 +0100
parents 9f121ca56cdb
children d4a8ae32b906
files jmh-core/src/main/java/org/openjdk/jmh/profile/GCProfiler.java
diffstat 1 files changed, 8 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/jmh-core/src/main/java/org/openjdk/jmh/profile/GCProfiler.java	Thu Dec 15 17:29:18 2016 +0100
+++ b/jmh-core/src/main/java/org/openjdk/jmh/profile/GCProfiler.java	Thu Dec 15 17:50:31 2016 +0100
@@ -325,6 +325,14 @@
             if (listener == null) {
                 throw new IllegalStateException("Churn profile already stopped");
             }
+
+            // Notifications are asynchronous, need to wait a bit before deregistering the listener.
+            try {
+                Thread.sleep(500);
+            } catch (InterruptedException e) {
+                // do not care
+            }
+
             for (GarbageCollectorMXBean bean : ManagementFactory.getGarbageCollectorMXBeans()) {
                 try {
                     ((NotificationEmitter) bean).removeNotificationListener(listener);