Resolve implicit concurrency problem

pull/137/head
johnniang 2019-03-22 16:21:19 +08:00
parent dfec650f79
commit 2184102c68
6 changed files with 11 additions and 13 deletions

View File

@ -8,7 +8,6 @@ import cc.ryanc.halo.service.OptionService;
import cc.ryanc.halo.utils.HaloUtils; import cc.ryanc.halo.utils.HaloUtils;
import cc.ryanc.halo.utils.ThemeUtils; import cc.ryanc.halo.utils.ThemeUtils;
import cc.ryanc.halo.web.controller.content.base.BaseContentController; import cc.ryanc.halo.web.controller.content.base.BaseContentController;
import cc.ryanc.halo.web.controller.support.PageJacksonSerializer;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONUtil; import cn.hutool.json.JSONUtil;
import freemarker.template.TemplateModelException; import freemarker.template.TemplateModelException;
@ -67,7 +66,8 @@ public class StartedListener implements ApplicationListener<ApplicationStartedEv
* Cache options to map * Cache options to map
*/ */
private void cacheOptions() { private void cacheOptions() {
HaloConst.OPTIONS = optionService.listOptions(); OPTIONS.clear();
OPTIONS.putAll(optionService.listOptions());
} }
/** /**

View File

@ -2,10 +2,10 @@ package cc.ryanc.halo.model.support;
import cn.hutool.json.JSONObject; import cn.hutool.json.JSONObject;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
/** /**
* <pre> * <pre>
@ -36,7 +36,7 @@ public class HaloConst {
/** /**
* All of the options * All of the options
*/ */
public static Map<String, String> OPTIONS; public final static ConcurrentMap<String, String> OPTIONS = new ConcurrentHashMap<>();
/** /**
* All of the Owo * All of the Owo

View File

@ -95,11 +95,9 @@ public class HaloUtils {
* @return default page size * @return default page size
*/ */
public static int getDefaultPageSize() { public static int getDefaultPageSize() {
if (StrUtil.isNotBlank(OPTIONS.get(BlogProperties.INDEX_POSTS))) { return Integer.valueOf(OPTIONS.getOrDefault(
return Integer.parseInt(OPTIONS.get(BlogProperties.INDEX_POSTS)); BlogProperties.INDEX_POSTS.getValue(),
} String.valueOf(DEFAULT_PAGE_SIZE)));
return DEFAULT_PAGE_SIZE;
} }
/** /**

View File

@ -62,7 +62,7 @@ public class ThemeController {
optionService.saveProperties(properties); optionService.saveProperties(properties);
BaseContentController.THEME = themeName; BaseContentController.THEME = themeName;
OPTIONS.clear(); OPTIONS.clear();
OPTIONS = optionService.listOptions(); OPTIONS.putAll(optionService.listOptions());
configuration.setSharedVariable("themeName", themeName); configuration.setSharedVariable("themeName", themeName);
configuration.setSharedVariable("options", OPTIONS); configuration.setSharedVariable("options", OPTIONS);
} }

View File

@ -30,7 +30,7 @@ public abstract class BaseController {
try { try {
OPTIONS.clear(); OPTIONS.clear();
THEMES.clear(); THEMES.clear();
OPTIONS = optionService.listOptions(); OPTIONS.putAll(optionService.listOptions());
THEMES = ThemeUtils.getThemes(); THEMES = ThemeUtils.getThemes();
configuration.setSharedVariable("options", OPTIONS); configuration.setSharedVariable("options", OPTIONS);
} catch (TemplateModelException e) { } catch (TemplateModelException e) {

View File

@ -295,7 +295,7 @@ public class InstallController {
menuService.create(menuArchive); menuService.create(menuArchive);
OPTIONS.clear(); OPTIONS.clear();
OPTIONS = optionService.listOptions(); OPTIONS.putAll(optionService.listOptions());
configuration.setSharedVariable("options", OPTIONS); configuration.setSharedVariable("options", OPTIONS);
// configuration.setSharedVariable("user", userService.findUser()); // configuration.setSharedVariable("user", userService.findUser());
} catch (Exception e) { } catch (Exception e) {