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.
*/
private String activatedThemeId;
private volatile String activatedThemeId;
/**
* Activated theme property.
*/
private ThemeProperty activatedTheme;
private volatile ThemeProperty activatedTheme;
public ThemeServiceImpl(HaloProperties haloProperties,
OptionService optionService,

View File

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