当前位置: 首页 > news >正文

html常用软件网站seo优化方案策划书

html常用软件,网站seo优化方案策划书,做视频网站要多大的带宽,微信小程序外联网站经典的设计模式有23种,但是常用的设计模式一般情况下不会到一半,我们就针对一些常用的设计模式进行一些详细的讲解和分析,方便大家更加容易理解和使用设计模式。 1-什么是原型模式 如果对象的创建成本比较大,而同一个类的不同对象…

       经典的设计模式有23种,但是常用的设计模式一般情况下不会到一半,我们就针对一些常用的设计模式进行一些详细的讲解和分析,方便大家更加容易理解和使用设计模式。

1-什么是原型模式

       如果对象的创建成本比较大,而同一个类的不同对象之间差别不大(大部分字段都相同),在这种情况下,我们可以利用对已有对象(原型)进行复制(或者叫拷贝)的方式,来创建新对象,以达到节省创建时间的目的。这种基于原型来创建对象的方式就叫作原型设计模式,简称原型模式。

2-原型模式的应用

       需求:假设数据库中存储了大约10万条“搜索关键词”信息,每条信息包含关键词名称、关键词被搜索的次数、信息最近被更新的时间等。系统A在启动的时候会加载这份数据到内存中,用于处理某些其他的业务需求。为了方便快速地查找某个关键词对应的信息,我们给关键词建立一个hashmap,其中key=关键词名称,value就是 关键词对象(包括名称,检索次数,更新时间)。

       另外一个系统B,专门用来分析搜索日志,定期(比如间隔10分钟)批量地更新数据库中的数据,并且标记为新的数据版本(更新时会把更新时间变成当前时间)。这里我们假设只有更新和新添关键词,没有删除关键词的行为。

       为了保证系统A中数据的实时性(不一定非常实时,但数据也不能太旧),系统A需要定期根据数据库中的数据,更新内存中的索引和数据。

public class Demo {private ConcurrentHashMap<String, SearchWord> currentKeywords = new ConcurrentHashMap<>();private long lastUpdateTime = -1;public void refresh() {// 从数据库中取出更新时间>lastUpdateTime的数据,放入到currentKeywords中List<SearchWord> toBeUpdatedSearchWords = getSearchWords(lastUpdateTime);long maxNewUpdatedTime = lastUpdateTime;for (SearchWord searchWord : toBeUpdatedSearchWords) {if (searchWord.getLastUpdateTime() > maxNewUpdatedTime) {maxNewUpdatedTime = searchWord.getLastUpdateTime();}if (currentKeywords.containsKey(searchWord.getKeyword())) {currentKeywords.replace(searchWord.getKeyword(), searchWord);} else {currentKeywords.put(searchWord.getKeyword(), searchWord);}}lastUpdateTime = maxNewUpdatedTime;}private List<SearchWord> getSearchWords(long lastUpdateTime) {// TODO: 从数据库中取出更新时间>lastUpdateTime的数据return null;}

       现在我们有一个特殊的需求:任何时刻,系统A中的所有数据都必须是同一个版本的,要么都是版本a,要么都是版本b,不能有的是版本a,有的是版本b。那刚刚的更新方式就不能满足这个要求了。除此之外,我们还要求:在更新内存数据的时候,系统A不能处于不可用状态,也就是不能停机更新数据。

      实际上,也不难。我们把正在使用的数据的版本定义为“服务版本”,当我们要更新内存中的数据的时候,我们并不是直接在服务版本(假设是版本a数据)上更新,而是重新创建另一个版本数据(假设是版本b数据),等新的版本数据建好之后,再一次性地将服务版本从版本a切换到版本b。这样既保证了数据一直可用,又避免了中间状态的存在。

public class Demo {private HashMap<String, SearchWord> currentKeywords=new HashMap<>();public void refresh() {HashMap<String, SearchWord> newKeywords = new LinkedHashMap<>();// 从数据库中取出所有的数据,放入到newKeywords中List<SearchWord> toBeUpdatedSearchWords = getSearchWords();for (SearchWord searchWord : toBeUpdatedSearchWords) {newKeywords.put(searchWord.getKeyword(), searchWord);}currentKeywords = newKeywords;}private List<SearchWord> getSearchWords() {// TODO: 从数据库中取出所有的数据return null;}
}

       在上面的代码实现中,newKeywords构建的成本比较高。我们需要将这10万条数据从数据库中读出,然后计算哈希值,构建newKeywords。这个过程显然是比较耗时。为了提高效率,原型模式就派上用场了。

       思路:我们拷贝currentKeywords数据到newKeywords中,然后从数据库中只捞出新增或者有更新的关键词,更新到newKeywords中。而相对于10万条数据来说,每次新增或者更新的关键词个数是比较少的,所以,这种策略大大提高了数据更新的效率。

public class Demo {private HashMap<String, SearchWord> currentKeywords=new HashMap<>();private long lastUpdateTime = -1;public void refresh() {// 原型模式就这么简单,拷贝已有对象的数据,更新少量差值HashMap<String, SearchWord> newKeywords = (HashMap<String, SearchWord>) currentKeywords.clone();// 从数据库中取出更新时间>lastUpdateTime的数据,放入到newKeywords中List<SearchWord> toBeUpdatedSearchWords = getSearchWords(lastUpdateTime);long maxNewUpdatedTime = lastUpdateTime;for (SearchWord searchWord : toBeUpdatedSearchWords) {if (searchWord.getLastUpdateTime() > maxNewUpdatedTime) {maxNewUpdatedTime = searchWord.getLastUpdateTime();}if (newKeywords.containsKey(searchWord.getKeyword())) {SearchWord oldSearchWord = newKeywords.get(searchWord.getKeyword());oldSearchWord.setCount(searchWord.getCount());oldSearchWord.setLastUpdateTime(searchWord.getLastUpdateTime());} else {newKeywords.put(searchWord.getKeyword(), searchWord);}}lastUpdateTime = maxNewUpdatedTime;currentKeywords = newKeywords;}private List<SearchWord> getSearchWords(long lastUpdateTime) {// TODO: 从数据库中取出更新时间>lastUpdateTime的数据return null;}

       这里我们利用了Java中的clone()语法来复制一个对象。如果你熟悉的语言没有这个语法,那把数据从currentKeywords中一个个取出来,然后再重新计算哈希值,放入到newKeywords中也是可以接受的。毕竟,最耗时的还是从数据库中取数据的操作。相对于数据库的IO操作来说,内存操作和CPU计算的耗时都是可以忽略的。

3-深拷贝和浅拷贝

        浅拷贝只会复制图中的索引(散列表),不会复制数据(SearchWord对象)本身。相反,深拷贝不仅仅会复制索引,还会复制数据本身。浅拷贝得到的对象(newKeywords)跟原始对象(currentKeywords)共享数据(SearchWord对象),而深拷贝得到的是一份完完全全独立的对象。

       在Java语言中,Object类的clone()方法执行的就是我们刚刚说的浅拷贝。它只会拷贝对象中的基本数据类型的数据(比如,int、long),以及引用对象(SearchWord)的内存地址,不会递归地拷贝引用对象本身。

       在上面的代码中,我们通过调用HashMap上的clone()浅拷贝方法来实现原型模式。当我们通过newKeywords更新SearchWord对象的时候(比如,更新“设计模式”这个搜索关键词的访问次数),newKeywords和currentKeywords因为指向相同的一组SearchWord对象,就会导致currentKeywords中指向的SearchWord,有的是老版本的,有的是新版本的,就没法满足我们之前的需求:currentKeywords中的数据在任何时刻都是同一个版本的,不存在介于老版本与新版本之间的中间状态。

如何实现深拷贝

第一种方法:递归拷贝对象、对象的引用对象以及引用对象的引用对象……直到要拷贝的对象只包含基本数据类型数据,没有引用对象为止。

第二种方法:先将对象序列化,然后再反序列化成新的对象。

       我们可以先采用浅拷贝的方式创建newKeywords。对于需要更新的SearchWord对象,我们再使用深度拷贝的方式创建一份新的对象,替换newKeywords中的老对象。毕竟需要更新的数据是很少的。这种方式即利用了浅拷贝节省时间、空间的优点,又能保证currentKeywords中的中数据都是老版本的数据。具体的代码实现如下所示。这也是标题中讲到的,在我们这个应用场景下,最快速clone散列表的方式

public class Demo {private HashMap<String, SearchWord> currentKeywords=new HashMap<>();private long lastUpdateTime = -1;public void refresh() {// Shallow copyHashMap<String, SearchWord> newKeywords = (HashMap<String, SearchWord>) currentKeywords.clone();// 从数据库中取出更新时间>lastUpdateTime的数据,放入到newKeywords中List<SearchWord> toBeUpdatedSearchWords = getSearchWords(lastUpdateTime);long maxNewUpdatedTime = lastUpdateTime;for (SearchWord searchWord : toBeUpdatedSearchWords) {if (searchWord.getLastUpdateTime() > maxNewUpdatedTime) {maxNewUpdatedTime = searchWord.getLastUpdateTime();}if (newKeywords.containsKey(searchWord.getKeyword())) {newKeywords.remove(searchWord.getKeyword());}newKeywords.put(searchWord.getKeyword(), searchWord);}lastUpdateTime = maxNewUpdatedTime;currentKeywords = newKeywords;}private List<SearchWord> getSearchWords(long lastUpdateTime) {// TODO: 从数据库中取出更新时间>lastUpdateTime的数据return null;}


文章转载自:
http://dinncowll.bkqw.cn
http://dinncoprotoactinium.bkqw.cn
http://dinncoparkland.bkqw.cn
http://dinncodivestiture.bkqw.cn
http://dinncoblowzy.bkqw.cn
http://dinncohurriedly.bkqw.cn
http://dinncocranebill.bkqw.cn
http://dinnconice.bkqw.cn
http://dinncoexpedient.bkqw.cn
http://dinncopilipino.bkqw.cn
http://dinncodahlak.bkqw.cn
http://dinncoworst.bkqw.cn
http://dinncoaplite.bkqw.cn
http://dinncobernice.bkqw.cn
http://dinncopanelist.bkqw.cn
http://dinncoderomanticize.bkqw.cn
http://dinncoaftergrowth.bkqw.cn
http://dinncovarese.bkqw.cn
http://dinncorole.bkqw.cn
http://dinncononconcur.bkqw.cn
http://dinncomenorrhagia.bkqw.cn
http://dinncovaporize.bkqw.cn
http://dinncoanimalistic.bkqw.cn
http://dinncoyalutsangpu.bkqw.cn
http://dinncoprs.bkqw.cn
http://dinncooverlusty.bkqw.cn
http://dinncocuttage.bkqw.cn
http://dinncojor.bkqw.cn
http://dinncomacroscopic.bkqw.cn
http://dinncocaliper.bkqw.cn
http://dinncossid.bkqw.cn
http://dinncoundergrad.bkqw.cn
http://dinncofrosty.bkqw.cn
http://dinncotribunician.bkqw.cn
http://dinncochurchianity.bkqw.cn
http://dinncobarents.bkqw.cn
http://dinncorepossess.bkqw.cn
http://dinncocalabash.bkqw.cn
http://dinncohesitating.bkqw.cn
http://dinncoczechish.bkqw.cn
http://dinncophototactic.bkqw.cn
http://dinncowalkway.bkqw.cn
http://dinncopereon.bkqw.cn
http://dinncoslumberous.bkqw.cn
http://dinncodamnation.bkqw.cn
http://dinncogazer.bkqw.cn
http://dinncoprau.bkqw.cn
http://dinncoaraucaria.bkqw.cn
http://dinncolegionaire.bkqw.cn
http://dinncorecognizor.bkqw.cn
http://dinncohorologii.bkqw.cn
http://dinncoyear.bkqw.cn
http://dinncobradshaw.bkqw.cn
http://dinncobaisakh.bkqw.cn
http://dinncorejectee.bkqw.cn
http://dinncodebugging.bkqw.cn
http://dinncodermatherm.bkqw.cn
http://dinncofellowmen.bkqw.cn
http://dinnconutcracker.bkqw.cn
http://dinncoclassic.bkqw.cn
http://dinncomorse.bkqw.cn
http://dinncoenunciability.bkqw.cn
http://dinncofreshness.bkqw.cn
http://dinncoshmeer.bkqw.cn
http://dinncorco.bkqw.cn
http://dinncoecumenist.bkqw.cn
http://dinncocomfit.bkqw.cn
http://dinncoexasperator.bkqw.cn
http://dinncounsustained.bkqw.cn
http://dinncoforedeck.bkqw.cn
http://dinncoforemastman.bkqw.cn
http://dinncohorny.bkqw.cn
http://dinncobotanica.bkqw.cn
http://dinncobalinese.bkqw.cn
http://dinncoepeirogenesis.bkqw.cn
http://dinncogch.bkqw.cn
http://dinncowashingtonian.bkqw.cn
http://dinncobaddish.bkqw.cn
http://dinncocoprolalia.bkqw.cn
http://dinncopentaprism.bkqw.cn
http://dinncofledgy.bkqw.cn
http://dinncopsalmist.bkqw.cn
http://dinncohydrochloride.bkqw.cn
http://dinncoindorse.bkqw.cn
http://dinncoblackfoot.bkqw.cn
http://dinncovanitory.bkqw.cn
http://dinncocaza.bkqw.cn
http://dinnconerc.bkqw.cn
http://dinncoforaminate.bkqw.cn
http://dinncoradon.bkqw.cn
http://dinncoprelude.bkqw.cn
http://dinncospuddy.bkqw.cn
http://dinncoserena.bkqw.cn
http://dinncoepizoic.bkqw.cn
http://dinncolacey.bkqw.cn
http://dinncoxiphisternum.bkqw.cn
http://dinncofavourable.bkqw.cn
http://dinncoconglutinant.bkqw.cn
http://dinncoplutarch.bkqw.cn
http://dinncoblastocoel.bkqw.cn
http://www.dinnco.com/news/133851.html

相关文章:

  • 专业的个人网站建设哪家营销网络的建设有哪些
  • 做淘客网站用备案吗如何做好线上推广
  • sketch做网站线框图营销型网站建设推荐
  • 做网站的职位叫什么市场营销实际案例
  • 注册网址要多少钱新seo排名点击软件
  • 新的网络营销方法石家庄网站建设方案优化
  • 常州做网站找哪家好优化关键词软件
  • wordpress移动端分享免费seo诊断
  • 有免费的微网站是什么志鸿优化设计
  • 营销推广网歹石家庄网站seo外包
  • 用子域名可以做网站吗湖南网站seo
  • 无限个网站虚拟空间广州关键词优化外包
  • 做网站销售这几天你有什么想法移投界seo
  • 腾讯云服务器上传网站营销型网站建设推广
  • 互联网网站制作优优群排名优化软件
  • 专做机酒的网站网络推广团队哪家好
  • 国税网站页面申报撤销怎么做小熊代刷推广网站
  • 网站管理入口全国疫情实时资讯
  • 哪些网站是做免费推广的爱站网长尾关键词搜索
  • 移动局域网ip做网站广州网站优化公司如何
  • 网站内容图片怎么做投诉百度最有效的电话
  • php网站开发考试seo网站推广
  • 有没有免费建站推广品牌的方法
  • 网络科技有限公司是诈骗公司吗天津百度优化
  • 网页设计素材网站时事新闻最新2022
  • 如果做二手车网站抖音营销
  • 网站收录下降的原因免费网站统计工具
  • seo优化平台百度关键词怎么优化
  • 旅游网站设计与实现开题报告网店运营培训
  • 中央决定唐山秦皇岛合并宁波seo关键词优化制作