fix: volatile in double-checked locking (#799)

pull/800/head
Wu Yuncheng 2020-04-28 17:58:37 +08:00 committed by GitHub
parent 5eb47b617e
commit 532b7f0532
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 5 deletions

View File

@ -81,12 +81,12 @@ public class ThemeServiceImpl implements ThemeService {
/** /**
* Activated theme id. * Activated theme id.
*/ */
private String activatedThemeId; private volatile String activatedThemeId;
/** /**
* Activated theme property. * Activated theme property.
*/ */
private ThemeProperty activatedTheme; private volatile ThemeProperty activatedTheme;
public ThemeServiceImpl(HaloProperties haloProperties, public ThemeServiceImpl(HaloProperties haloProperties,
OptionService optionService, OptionService optionService,

View File

@ -19,7 +19,7 @@ import java.util.*;
*/ */
public class ValidationUtils { public class ValidationUtils {
private static Validator VALIDATOR; private static volatile Validator VALIDATOR;
private ValidationUtils() { private ValidationUtils() {
} }
@ -33,10 +33,12 @@ public class ValidationUtils {
public static Validator getValidatorOrCreate() { public static Validator getValidatorOrCreate() {
if (VALIDATOR == null) { if (VALIDATOR == null) {
synchronized (ValidationUtils.class) { synchronized (ValidationUtils.class) {
if (VALIDATOR == null) {
// Init the validation // Init the validation
VALIDATOR = Validation.buildDefaultValidatorFactory().getValidator(); VALIDATOR = Validation.buildDefaultValidatorFactory().getValidator();
} }
} }
}
return VALIDATOR; return VALIDATOR;
} }