+ * {@link https://en.wikipedia.org/wiki/Race_condition}
+ * {@link https://en.wikipedia.org/wiki/Compare-and-swap}
+ */
+ public void init() {
+ if (isNotInitialized()) {
+ synchronized (atomicReference) {
+ if (isNotInitialized()) { // double check if was initialized
+ validator.rules();
+ final Boolean oldValue = atomicReference.get();
+ final Boolean newValue = Boolean.TRUE;
+ atomicReference.compareAndSet(oldValue, newValue);
+ }
}
}
+ }
+
+ private boolean isNotInitialized() {
+ return Boolean.FALSE.equals(atomicReference.get());
+ }
- };
+ }
+
+ protected AbstractValidator() {
+ this.initialize = new Initializer<>(this);
}
/**
@@ -114,7 +138,7 @@ public