private void scheduleHeartbeat ( ) { // elapsed time in seconds since the last heartbeat long elapsedSecsSinceLastHeartBeat = System . currentTimeMillis ( ) / 1000 - lastHeartbeatStartTimeInSecs ; /* * The initial delay for the new scheduling is 0 if the elapsed * time is more than the heartbeat time interval, otherwise it is the * difference between the heartbeat time interval and the elapsed time. */ long initialDelay = Math . max ( heartBeatIntervalInSecs - elapsedSecsSinceLastHeartBeat , 0 ) ; LOGGER . debug ( "schedule heartbeat task with initial delay of {} seconds" , initialDelay ) ; // Creates and executes a periodic action to send heartbeats this . heartbeatFuture = this . scheduler . schedule ( this , initialDelay , TimeUnit . SECONDS ) ; }
Schedule the next heartbeat