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

[ISSUE#12583] ProtocolManager代码优化 #12584

Merged
merged 2 commits into from
Sep 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,13 @@ public class ProtocolManager extends MemberChangeListener implements DisposableB

private final ServerMemberManager memberManager;

private boolean apInit = false;
private volatile boolean apInit = false;

private boolean cpInit = false;
private volatile boolean cpInit = false;

private final Object cpLock = new Object();

private final Object apLock = new Object();

private Set<Member> oldMembers;

Expand All @@ -80,20 +84,24 @@ public static Set<String> toCPMembersInfo(Collection<Member> members) {
}

public CPProtocol getCpProtocol() {
synchronized (this) {
if (!cpInit) {
initCPProtocol();
cpInit = true;
if (!cpInit){
synchronized (cpLock) {
if (!cpInit) {
initCPProtocol();
cpInit = true;
}
}
}
return cpProtocol;
}

public APProtocol getApProtocol() {
synchronized (this) {
if (!apInit) {
initAPProtocol();
apInit = true;
if (!apInit) {
synchronized (apLock) {
if (!apInit) {
initAPProtocol();
apInit = true;
}
}
}
return apProtocol;
Expand Down
Loading