Skip to content

Commit

Permalink
Merge pull request #2 from hucaicai/main
Browse files Browse the repository at this point in the history
client端与server连接初始化后启动心跳任务
  • Loading branch information
liuliuwd authored Aug 19, 2022
2 parents acb1eb3 + 280e6ba commit 73b834a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import com.wuba.wlock.client.registryclient.entity.ClientKeyEntity;
import com.wuba.wlock.client.registryclient.entity.NodeAddr;
import com.wuba.wlock.client.registryclient.registrykey.RegistryKey;
import com.wuba.wlock.client.service.HeartbeatService;
import com.wuba.wlock.client.util.TimeUtil;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
Expand Down Expand Up @@ -60,6 +61,7 @@ private ServerPoolHandler(WLockClient wlockClient) throws IOException, Execution
this.wlockClient = wlockClient;
this.registryKey = wlockClient.getRegistryKey();
initSeverPool();
HeartbeatService.getHbService().start();
}

public void initSeverPool() throws IOException, ExecutionException, InterruptedException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
public class HeartbeatService {
private static final Log logger = LogFactory.getLog(HeartbeatService.class);

public AtomicBoolean started = new AtomicBoolean(true);
public AtomicBoolean started = new AtomicBoolean(false);
private int initialDelay = 30;
private int period = (new Random().nextInt(4) + 2);
private ConcurrentHashMap<String, Integer> serverDetectMap = new ConcurrentHashMap<String, Integer>(128);
Expand All @@ -48,18 +48,23 @@ public class HeartbeatService {
public static HeartbeatService hbService = new HeartbeatService();

private HeartbeatService() {
Thread thread = new Thread(new HeartbeatWorker());
thread.setName("WLock HeartbeatDetectThread");
thread.setDaemon(true);
thread.start();

logger.info(Version.INFO + ", start heartbeat detect job success.");
}

public static HeartbeatService getHbService() {
return hbService;
}

public void start() {
if (started.compareAndSet(false, true)) {
Thread thread = new Thread(new HeartbeatWorker());
thread.setName("WLock HeartbeatDetectThread");
thread.setDaemon(true);
thread.start();

logger.info(Version.INFO + ", start heartbeat detect job success.");
}
}

private void sendHeartbeat() {
// 清理脏数据
if (clearCount.incrementAndGet() > heartbeatMaxTimes) {
Expand Down

0 comments on commit 73b834a

Please sign in to comment.