Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

选举Leader细节问题 #5

Open
Zouxxyy opened this issue Apr 16, 2020 · 1 comment
Open

选举Leader细节问题 #5

Zouxxyy opened this issue Apr 16, 2020 · 1 comment

Comments

@Zouxxyy
Copy link

Zouxxyy commented Apr 16, 2020

选举Leader的一个需求是 candidate 请求投票时,如果有超过半数的响应为 success,就获选leader。

但这处代码的实现是:通过 CountDownLatch(size)阻塞实现,且是在全部都响应了才开始判断。

而且这部分的异步任务处理 分提交和检测完成两次,觉得写的有点繁琐。个人觉得可使用一个ExecutorCompletionService,写起来更清晰,同时在每次take后检测是否有超过半数的成功响应。

@Zouxxyy Zouxxyy changed the title 选举Leader细节bug 选举Leader细节问题 Apr 16, 2020
@kebukeYi
Copy link

CountDownLatch latch_1 = new CountDownLatch(futureArrayList.size() / 2);
把全部 改为 一半 怎么样?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants