Optimize client health check time delay mechanism (#450)

pull/467/head
linlinjie 2 years ago committed by GitHub
parent 3d52b473de
commit 8e7e62c2f5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -17,6 +17,7 @@
package cn.hippo4j.springboot.starter.remote;
import cn.hippo4j.common.toolkit.ThreadUtil;
import cn.hippo4j.springboot.starter.event.ApplicationCompleteEvent;
import cn.hippo4j.springboot.starter.core.ShutdownExecuteException;
import cn.hippo4j.core.executor.support.ThreadFactoryBuilder;
@ -47,6 +48,11 @@ public abstract class AbstractHealthCheck implements ServerHealthCheck, Initiali
*/
private volatile boolean healthStatus = true;
/**
* Health check failure count
*/
private volatile int checkFailureCount = 0;
/**
* Client shutdown hook
*/
@ -89,11 +95,18 @@ public abstract class AbstractHealthCheck implements ServerHealthCheck, Initiali
if (healthCheckStatus) {
if (Objects.equals(healthStatus, false)) {
healthStatus = true;
checkFailureCount = 0;
log.info("The client reconnects to the server successfully.");
signalAllBizThread();
}
} else {
healthStatus = false;
checkFailureCount++;
if (checkFailureCount > 1 && checkFailureCount < 4) {
ThreadUtil.sleep(HEALTH_CHECK_INTERVAL * 1000 * (checkFailureCount - 1));
} else if (checkFailureCount >= 4) {
ThreadUtil.sleep(25000L);
}
}
}

Loading…
Cancel
Save