Fix beat task never execute bug
This commit is contained in:
parent
cc33ccd1ad
commit
a8ead77f6f
@ -23,21 +23,21 @@ import com.alibaba.nacos.client.naming.utils.UtilAndComs;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* @author harold
|
||||
*/
|
||||
public class BeatReactor {
|
||||
|
||||
private ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor(new ThreadFactory() {
|
||||
@Override
|
||||
public Thread newThread(Runnable r) {
|
||||
private ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor(r -> {
|
||||
Thread thread = new Thread(r);
|
||||
thread.setDaemon(true);
|
||||
thread.setName("com.alibaba.nacos.naming.beat.sender");
|
||||
return thread;
|
||||
}
|
||||
});
|
||||
|
||||
private long clientBeatInterval = 10 * 1000;
|
||||
@ -48,7 +48,7 @@ public class BeatReactor {
|
||||
|
||||
public BeatReactor(NamingProxy serverProxy) {
|
||||
this.serverProxy = serverProxy;
|
||||
executorService.execute(new BeatProcessor());
|
||||
executorService.scheduleAtFixedRate(new BeatProcessor(), 0, clientBeatInterval, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
||||
public void addBeatInfo(String dom, BeatInfo beatInfo) {
|
||||
@ -63,21 +63,17 @@ public class BeatReactor {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
while (true) {
|
||||
try {
|
||||
for (Map.Entry<String, BeatInfo> entry : dom2Beat.entrySet()) {
|
||||
BeatInfo beatInfo = entry.getValue();
|
||||
executorService.schedule(new BeatTask(beatInfo), 0, TimeUnit.MILLISECONDS);
|
||||
LogUtils.LOG.info("BEAT", "send beat to server: ", beatInfo.toString());
|
||||
}
|
||||
|
||||
TimeUnit.MILLISECONDS.sleep(clientBeatInterval);
|
||||
} catch (Exception e) {
|
||||
LogUtils.LOG.error("CLIENT-BEAT", "Exception while scheduling beat.", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class BeatTask implements Runnable {
|
||||
BeatInfo beatInfo;
|
||||
|
Loading…
Reference in New Issue
Block a user