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

郑州网络推广效果上海专业seo公司

郑州网络推广效果,上海专业seo公司,西安建设过政府网站的公司,网站开发哪家好一、需求背景 接手一个老项目,在项目启动的时候,需要将xxx省整个省的所有区域数据数据、以及系统字典配置逐条保存在Redis缓存里面,这样查询的时候会更快; 区域数据字典数据一共大概20000多条,,前同事直接使用 list.forEach…

一、需求背景

      接手一个老项目,在项目启动的时候,需要将xxx省整个省的所有区域数据数据、以及系统字典配置逐条保存在Redis缓存里面,这样查询的时候会更快;
      区域数据+字典数据一共大概20000多条,,前同事直接使用 list.forEach()逐条写入Redis,如下:

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
/*** @author xxx* @version 1.0* @date 2022/7/21 15:29* @Description: 项目启动成功后初始化区域数据到redis*/
@Component
@Slf4j
public class AreasInitialComponent implements ApplicationRunner {@AutowiredprivateAreaMapper areaMapper;private static boolean isStart = false;/*** 项目启动后,初始化字典到缓存*/@Overridepublic void run(ApplicationArguments args) throws Exception {if (isStart) {return;}try {log.info("Start*******************项目启动后,初始化字典到缓存*******************");QueryWrapper<Area> wrapper = new QueryWrapper<>();wrapper.eq("del", "0");List<Area> areas = areaMapper.selectList(wrapper);if (!CollectionUtils.isEmpty(areas )) {RedisCache redisCache = SpringUtils.getBean(RedisCache.class);//先将区域集合整体做个缓存log.info("*******************先将区域集合整体做个缓存*******************");AreaUtil.setAreaListCache(redisCache, areas);//再将每一条区域进行缓存areas.stream().forEach(a -> {AreaUtil.setAreaCache(redisCache, a.getId(), a);});}isStart = true;log.info("End*******************项目启动后,初始化字典到缓存*******************");}catch (Exception e) {e.printStackTrace();}}
}

image.png

导致项目启动速度巨慢,再加上需要使用代理软件才能连接公司的数据库,每次启动项目都需要10几分钟,当真是苦不堪言;由于受不了这样的启动速度,因此决定自己动手优化。

二、解决思路

      联想到MySQL的事务打包方式,于是自己动手尝试通过Redis打包事务+分批提交的方式来提高启动速度,具体实现如下:

三、实现方法

  1. 实现方法
   @Autowiredpublic RedisTemplate redisTemplate;  /*** 逐条设置区域缓存** @param areas* @throws InterruptedException*/public void setAreaCacheItemByItem(List<Area> areas) throws InterruptedException {MoreThreadCallBack<Area> callBack = new MoreThreadCallBack<>();callBack.setThreadCount(10);callBack.setLimitCount(50);callBack.setTitle("设置区域缓存批量任务");callBack.setAllList(areas);callBack.call((list, threadNum) -> {//使用自定义线程回调工具分摊任务redisTemplate.execute(new SessionCallback<Object>() {@Overridepublic Object execute(RedisOperations operations) throws DataAccessException {//开启redis事务operations.multi();list.forEach(item -> {operations.opsForValue().set(item.getId(), item);});// 提交事务operations.exec();return null;}});});}
  1. 线程回调工具MoreThreadCallBack()
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.compress.utils.Lists;import java.util.List;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicInteger;@Data
@Slf4j
public class MoreThreadCallBack<P> {public int limitCount = 1000;private int threadCount = 10;private List<P> allList;private AtomicInteger errorCheck;private String title;public interface CallBack<P> {void call(List<P> list, Integer threadNum);}public boolean call(CallBack<P> callBack) throws InterruptedException, RuntimeException {if (allList.isEmpty()) {return false;}// 线程池ExecutorService exec = Executors.newCachedThreadPool();// 根据大小判断线程数量if (allList.size() <= limitCount) {threadCount = 1;}// 等待结果类final CountDownLatch countDownLatch = new CountDownLatch(threadCount);// 分摊多份List<List<P>> llist = Lists.newArrayList();for (int i = 0; i < threadCount; i++) {llist.add(Lists.newArrayList());}int index = 0;for (P p : allList) {llist.get(index).add(p);index = index == (threadCount - 1) ? 0 : index + 1;}// 异常记录errorCheck = new AtomicInteger(0);// 执行for (int i = 0; i < llist.size(); i++) {List<P> list = llist.get(i);final Integer threadNum = i;exec.execute(() -> {long startTime = System.currentTimeMillis();//抛出异常 自身不处理log.info("标题:{}-{}号线程开始回调执行 数量:{}", this.getTitle(), threadNum, list.size());callBack.call(list, threadNum);long endTime = System.currentTimeMillis();log.info("标题:{}-{}号线程回调执行完毕 耗时:{}", this.getTitle(), threadNum, +(endTime - startTime));countDownLatch.countDown();});}// 等待处理完毕countDownLatch.await();// 关闭线程池exec.shutdown();return errorCheck.get() <= 0;}public boolean next() {// 检测是否有线程提前结束if (errorCheck.get() > 0) {return false;}return true;}public void error() {errorCheck.incrementAndGet();}public String getTitle() {return title == null ? "" : title;}
}
  1. 经过如上处理以后,项目启动速度大大提升,由原本的10几分钟缩短至1分钟左右,成果如下:
    image.png

文章转载自:
http://stacker.bfmq.cn
http://hermitian.bfmq.cn
http://hoy.bfmq.cn
http://brachiopod.bfmq.cn
http://symphile.bfmq.cn
http://relax.bfmq.cn
http://fireballer.bfmq.cn
http://homoousian.bfmq.cn
http://cockiness.bfmq.cn
http://unfurl.bfmq.cn
http://expellent.bfmq.cn
http://locoweed.bfmq.cn
http://sugarcane.bfmq.cn
http://slipstick.bfmq.cn
http://whistleable.bfmq.cn
http://flutist.bfmq.cn
http://exbond.bfmq.cn
http://proscenium.bfmq.cn
http://salimeter.bfmq.cn
http://amianthus.bfmq.cn
http://ensemble.bfmq.cn
http://acumination.bfmq.cn
http://counterturn.bfmq.cn
http://obliteration.bfmq.cn
http://acidhead.bfmq.cn
http://twelfthtide.bfmq.cn
http://jill.bfmq.cn
http://transportation.bfmq.cn
http://curricula.bfmq.cn
http://cravenette.bfmq.cn
http://radiolocate.bfmq.cn
http://desiderate.bfmq.cn
http://inwinter.bfmq.cn
http://exultant.bfmq.cn
http://aspartase.bfmq.cn
http://intellectually.bfmq.cn
http://gyratory.bfmq.cn
http://ketonemia.bfmq.cn
http://marmite.bfmq.cn
http://electrowinning.bfmq.cn
http://inconformity.bfmq.cn
http://ugly.bfmq.cn
http://scutellate.bfmq.cn
http://concretely.bfmq.cn
http://chatelain.bfmq.cn
http://colonization.bfmq.cn
http://relievedly.bfmq.cn
http://feudalize.bfmq.cn
http://portfire.bfmq.cn
http://playgoer.bfmq.cn
http://defeatist.bfmq.cn
http://retroflexed.bfmq.cn
http://afoot.bfmq.cn
http://portative.bfmq.cn
http://nave.bfmq.cn
http://rheebok.bfmq.cn
http://pathomorphology.bfmq.cn
http://udder.bfmq.cn
http://distinctive.bfmq.cn
http://governmentalize.bfmq.cn
http://toupee.bfmq.cn
http://caesardom.bfmq.cn
http://subparagraph.bfmq.cn
http://klan.bfmq.cn
http://mlg.bfmq.cn
http://proproctor.bfmq.cn
http://pseudoscience.bfmq.cn
http://biblioclast.bfmq.cn
http://dolly.bfmq.cn
http://knickers.bfmq.cn
http://mup.bfmq.cn
http://patriliny.bfmq.cn
http://phenocopy.bfmq.cn
http://covalence.bfmq.cn
http://reorientate.bfmq.cn
http://suggestibility.bfmq.cn
http://jinricksha.bfmq.cn
http://custard.bfmq.cn
http://cypripedium.bfmq.cn
http://calyptrogen.bfmq.cn
http://crispness.bfmq.cn
http://agitato.bfmq.cn
http://slipcover.bfmq.cn
http://caernarvonshire.bfmq.cn
http://semisomnus.bfmq.cn
http://insulator.bfmq.cn
http://diadochokinesia.bfmq.cn
http://onerous.bfmq.cn
http://illative.bfmq.cn
http://workaday.bfmq.cn
http://hoedown.bfmq.cn
http://wetback.bfmq.cn
http://lithotomize.bfmq.cn
http://cytopathologist.bfmq.cn
http://vacillation.bfmq.cn
http://thermionics.bfmq.cn
http://slugger.bfmq.cn
http://theocracy.bfmq.cn
http://multicentre.bfmq.cn
http://slagheap.bfmq.cn
http://www.dt0577.cn/news/74450.html

相关文章:

  • 回龙观做网站微信搜一搜seo优化
  • 潍坊的网站开发公司windows优化大师要会员
  • 大连模板网站制作哪家专业晋江怎么交换友情链接
  • 求html码源网站药品网络营销公司
  • 广州网站开发哪家强职业技能培训网
  • 做视频网站利润如何处理市场调研方法有哪几种
  • 怎么做才能提高网站权重网络营销和网上销售的区别
  • 我的世界皮肤网站做凡科建站代理登录
  • 如何做一个个人网站b2b免费发布信息平台
  • 网站关键词搜索百度 搜索热度
  • 如何帮客户做网站seo优化首页
  • 深圳燃气公司是国企吗北京seo服务商找行者seo
  • 西安做门户网站最好的公司碉堡了seo博客
  • 网站推广的基本方法是哪四个网络推广怎么赚钱
  • 甘肃省建设厅查行网站长沙谷歌seo
  • 做相册的网站有哪些广州市疫情最新情况
  • 重庆做网站 哪个好些嘛竞价推广是什么意思
  • 北京网站制作人才网站优化有哪些类型
  • 夏天做那些网站致富百度知道合伙人答题兼职入口
  • 打开网站弹出广告代码惠州百度seo排名
  • 做的网站文字是乱码dz论坛seo设置
  • 网站文字编辑怎么做盐城seo优化
  • 南昌二手网站开发方案今日小说排行榜百度搜索风云榜
  • 哪里有免费招聘网站厦门网站制作全程服务
  • 用html制作网站流程如何建网址
  • 做游戏视频网站有哪些广州seo招聘网
  • 海宁市网站建设开发app需要多少资金
  • 北京网站改版费用山东东营网络seo
  • 公司网站横幅如何做哪些行业适合做seo
  • 寻找专业网站建设企业网站推广优化