@@ -383,7 +383,12 @@ private void scheduleHeartbeatImpl(boolean immediately) {
383
383
while (appsI .hasNext ()) if (appsI .next ().isRemoved ()) appsI .remove ();
384
384
if (apps .isEmpty ()) {
385
385
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
+ }
387
392
}
388
393
389
394
final AtomicInteger counter = new AtomicInteger (apps .size ());
@@ -420,18 +425,19 @@ public void propertyChange(PropertyChangeEvent evt) {
420
425
}
421
426
} finally {
422
427
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
+ }
424
436
425
- if (! anotherHeartbeatPending ) {
437
+ if (anotherHeartbeatPending || pendingApps ) {
426
438
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 );
432
440
}
433
-
434
- if (!heartbeatRunning ) scheduleHeartbeatImpl (false ); // start again if needed and not running yet
435
441
}
436
442
}
437
443
}
0 commit comments