国产亚洲精品福利在线无卡一,国产精久久一区二区三区,亚洲精品无码国模,精品久久久久久无码专区不卡

當前位置: 首頁 > news >正文

網(wǎng)站開發(fā)工程師面試問哪些問題網(wǎng)絡(luò)營銷推廣渠道

網(wǎng)站開發(fā)工程師面試問哪些問題,網(wǎng)絡(luò)營銷推廣渠道,政府網(wǎng)站建設(shè)的現(xiàn)狀,網(wǎng)頁畢業(yè)設(shè)計作品寫享元模式的時候,會想使用ConcurrentHashMap來保證并發(fā),沒有使用雙重鎖會不會有問題?但是在synchronize代碼塊里面需要盡量避免throw異常,希望有經(jīng)驗的同學(xué)能夠給出解答? 1月6號補充:沒有使用雙重鎖會有問…

寫享元模式的時候,會想使用ConcurrentHashMap來保證并發(fā),沒有使用雙重鎖會不會有問題?但是在synchronize代碼塊里面需要盡量避免throw異常,希望有經(jīng)驗的同學(xué)能夠給出解答?

1月6號補充:沒有使用雙重鎖會有問題

享元模式UML圖如下:
在這里插入圖片描述

@Component
public class PayContextFactory extends AbstractPayContextFactory<PayContext> {//享元模式private static final Map<String, PayContext> payContexts = new ConcurrentHashMap<>();@Overridepublic PayContext getContext(Integer payType) {StrategyEnum strategyEnum =payType == 1 ? StrategyEnum.alipay :payType == 2 ? StrategyEnum.wechat :null;if (Objects.isNull(strategyEnum)) {throw new UnsupportedOperationException("payType not supported!");}//嘗試從map中獲取ContextPayContext context = payContexts.get(strategyEnum.name());//第一次調(diào)用if (Objects.isNull(context)) {try {//通過反射,創(chuàng)建具體類PayStrategyInterface payStrategy = (PayStrategyInterface) Class.forName(strategyEnum.getValue()).newInstance();//將具體策略類作為入?yún)?創(chuàng)建payContextPayContext payContext = new PayContext(payStrategy);payContexts.put(strategyEnum.name(), payContext);} catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) {throw new UnsupportedOperationException("get strategy failed!");}}return payContexts.get(strategyEnum.name());}
}

使用雙重檢查鎖后的代碼

@Component
public class PayContextFactory extends AbstractPayContextFactory<PayContext> {//享元模式private static final Map<String, PayContext> payContexts = new ConcurrentHashMap<>();@Overridepublic PayContext getContext(Integer payType) {StrategyEnum strategyEnum =payType == 1 ? StrategyEnum.alipay :payType == 2 ? StrategyEnum.wechat :null;if (Objects.isNull(strategyEnum)) {throw new UnsupportedOperationException("payType not supported!");}//嘗試從map中獲取ContextPayContext context = payContexts.get(strategyEnum.name());//第一次調(diào)用if (Objects.isNull(context)) {synchronized (payContexts) {context = payContexts.get(strategyEnum.name());if (Objects.isNull(context)) {try {//通過反射,創(chuàng)建具體類PayStrategyInterface payStrategy = (PayStrategyInterface) Class.forName(strategyEnum.getValue()).newInstance();//將具體策略類作為入?yún)?創(chuàng)建payContextPayContext payContext = new PayContext(payStrategy);payContexts.put(strategyEnum.name(), payContext);} catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) {throw new UnsupportedOperationException("get strategy failed!");}}}}return payContexts.get(strategyEnum.name());}
}
http://aloenet.com.cn/news/28880.html

相關(guān)文章:

  • 電子商務(wù)網(wǎng)站建設(shè)費用百度官方免費下載安裝
  • 找人做網(wǎng)站沒有做好報案有用嗎指數(shù)網(wǎng)站
  • 有沒有好的做海報的網(wǎng)站seo sem是指什么意思
  • 網(wǎng)站備案期間能使用嗎百度seo發(fā)包工具
  • unity做網(wǎng)站做銷售有什么技巧和方法
  • 外貿(mào)企業(yè)網(wǎng)站功能要求網(wǎng)店推廣的作用是
  • 南通網(wǎng)站群建設(shè)網(wǎng)絡(luò)廣告電話
  • 臨淄網(wǎng)站推廣烏魯木齊seo
  • 正規(guī)品牌網(wǎng)站設(shè)計推薦seo網(wǎng)站優(yōu)化多少錢
  • 做網(wǎng)站優(yōu)化的弊端如何在百度上建立網(wǎng)站
  • 公司做網(wǎng)站可以用個人域名app拉新任務(wù)平臺
  • 濮陽做網(wǎng)站免費推廣引流app
  • wordpress 外貿(mào)站網(wǎng)站建設(shè)怎么弄
  • 做家務(wù)的男人免費觀看網(wǎng)站搭建網(wǎng)站平臺需要多少錢
  • 做賭博網(wǎng)站會被判多久上海搜索引擎優(yōu)化seo
  • 桂林遇龍河優(yōu)化大師有必要安裝嗎
  • 網(wǎng)站制作培訓(xùn)費用seo和競價排名的區(qū)別
  • 要想瀏覽國外網(wǎng)站 應(yīng)該怎么做特色產(chǎn)品推廣方案
  • 免費二級域名備案解析seo優(yōu)化診斷工具
  • 電腦買編程代碼做網(wǎng)站應(yīng)用下載app排行榜
  • 麗水做網(wǎng)站公司利于seo的建站系統(tǒng)有哪些
  • 舟山論壇網(wǎng)站建設(shè)公司怎么推廣網(wǎng)絡(luò)營銷
  • 可以做h5游戲的網(wǎng)站谷歌是如何運營的
  • 做面包有哪些網(wǎng)站知乎快速優(yōu)化系統(tǒng)
  • 那個網(wǎng)站教做仙芋鮮企業(yè)網(wǎng)站建設(shè)的一般要素
  • 用第三方做網(wǎng)站北京seo包年
  • 說做網(wǎng)站被收債正規(guī)淘寶代運營去哪里找
  • 簡約網(wǎng)站模板廣州seo優(yōu)化排名公司
  • 重慶seo整站優(yōu)化外包服務(wù)最新消息
  • 文網(wǎng)文網(wǎng)站建設(shè)2024年陽性最新癥狀