比如秒杀网关业务场景
@Component
public class SecKillProductConfig implements InitializingBean { private static final Map<String, SecKillProductDobj> PRODUCT_CONFIG_MAP =
new ConcurrentHashMap<>(16); @PostConstruct
public void init() {
List<SecKillProductDobj> killProductList = secKillProductService.querySecKillProductList();
if (killProductList == null) {
throw new RuntimeException("请确保数据库中存在秒杀商品配置!");
}
killProductList.stream().forEach((secKillProductDobj -> {
String prodId = secKillProductDobj.getProdId();
PRODUCT_CONFIG_MAP.put(prodId, secKillProductDobj);
}));
LOGGER.info("[SecKillProductConfig]初始化秒杀配置完成,商品信息=[{}]", JSON.toJSONString(PRODUCT_CONFIG_MAP));
}这里的ConcurrentHashMap能不能换成HashMap?
@Component
public class SecKillProductConfig implements InitializingBean { private static final Map<String, SecKillProductDobj> PRODUCT_CONFIG_MAP =
new ConcurrentHashMap<>(16); @PostConstruct
public void init() {
List<SecKillProductDobj> killProductList = secKillProductService.querySecKillProductList();
if (killProductList == null) {
throw new RuntimeException("请确保数据库中存在秒杀商品配置!");
}
killProductList.stream().forEach((secKillProductDobj -> {
String prodId = secKillProductDobj.getProdId();
PRODUCT_CONFIG_MAP.put(prodId, secKillProductDobj);
}));
LOGGER.info("[SecKillProductConfig]初始化秒杀配置完成,商品信息=[{}]", JSON.toJSONString(PRODUCT_CONFIG_MAP));
}这里的ConcurrentHashMap能不能换成HashMap?
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货