Skip to content

Commit

Permalink
fix: Replace double-checked locking idiom with initialization-on-dema…
Browse files Browse the repository at this point in the history
  • Loading branch information
manusa committed Feb 18, 2021
1 parent b68aa7e commit 6d93cbc
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,12 @@ public class Readiness {
protected static final String READINESS_APPLICABLE_RESOURCES =
"Node, Deployment, ReplicaSet, StatefulSet, Pod, ReplicationController";

private static Readiness instance;
private static class ReadinessHolder {
public static final Readiness INSTANCE = new Readiness();
}

public static Readiness getInstance() {
if (instance == null) {
synchronized (Readiness.class) {
instance = new Readiness();
}
}
return instance;
return ReadinessHolder.INSTANCE;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,12 @@ public class OpenShiftReadiness extends Readiness {
private static final String OPENSHIFT_READINESS_APPLICABLE_RESOURCES = READINESS_APPLICABLE_RESOURCES +
", " + "DeploymentConfig";

private static OpenShiftReadiness instance;
private static class OpenShiftReadinessHolder {
public static final OpenShiftReadiness INSTANCE = new OpenShiftReadiness();
}

public static OpenShiftReadiness getInstance() {
if (instance == null) {
synchronized (OpenShiftReadiness.class) {
instance = new OpenShiftReadiness();
}
}
return instance;
return OpenShiftReadinessHolder.INSTANCE;
}

@Override
Expand Down

0 comments on commit 6d93cbc

Please sign in to comment.