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