Skip to content

Commit be648ab

Browse files
committed
JMX heartbeat fixes & improvements
1 parent 9cd6859 commit be648ab

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

visualvm/jmx/src/org/graalvm/visualvm/jmx/impl/JmxApplicationProvider.java

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,12 @@ private void scheduleHeartbeatImpl(boolean immediately) {
383383
while (appsI.hasNext()) if (appsI.next().isRemoved()) appsI.remove();
384384
if (apps.isEmpty()) {
385385
heartbeatRunning = false;
386-
return;
386+
if (anotherHeartbeatPending) { // just a safe fallback, likely not needed at all
387+
anotherHeartbeatPending = false;
388+
scheduleHeartbeatImpl(false);
389+
} else {
390+
return;
391+
}
387392
}
388393

389394
final AtomicInteger counter = new AtomicInteger(apps.size());
@@ -420,18 +425,19 @@ public void propertyChange(PropertyChangeEvent evt) {
420425
}
421426
} finally {
422427
if (counter.decrementAndGet() == 0) {
423-
heartbeatRunning = false; // done
428+
boolean pendingApps;
429+
430+
synchronized (unavailableApps) {
431+
Iterator<JmxApplication> appsI = unavailableApps.iterator();
432+
while (appsI.hasNext()) if (appsI.next().isRemoved()) appsI.remove();
433+
pendingApps = !unavailableApps.isEmpty();
434+
heartbeatRunning = false;
435+
}
424436

425-
if (!anotherHeartbeatPending) {
437+
if (anotherHeartbeatPending || pendingApps) {
426438
anotherHeartbeatPending = false;
427-
synchronized (unavailableApps) {
428-
Iterator<JmxApplication> appsI = unavailableApps.iterator();
429-
while (appsI.hasNext()) if (appsI.next().isRemoved()) appsI.remove();
430-
if (unavailableApps.isEmpty()) return; // not pending and no apps to check, return
431-
}
439+
scheduleHeartbeatImpl(false);
432440
}
433-
434-
if (!heartbeatRunning) scheduleHeartbeatImpl(false); // start again if needed and not running yet
435441
}
436442
}
437443
}

0 commit comments

Comments
 (0)