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

什么是网站改版电商seo与sem是什么

什么是网站改版,电商seo与sem是什么,做网站公司的年终总结,网站建设有前途吗java分布式&锁&分布式锁 锁 锁的作用:有限资源的情况下,控制同一时间段,只有某些线程(用户/服务器)能访问到资源。 锁在java中的实现: synchronized关键字并发包的类 缺点:只对单个的…

java分布式&锁&分布式锁

  1. 锁的作用:有限资源的情况下,控制同一时间段,只有某些线程(用户/服务器)能访问到资源。
    在这里插入图片描述
  2. 锁在java中的实现:
    • synchronized关键字
    • 并发包的类
  3. 缺点:只对单个的jvm有效
    在这里插入图片描述

分布式锁

  1. 为什么实现分布式锁
    • 有限资源的情况下,控制同一段时间只有某些用户/服务器才能访问到资源
    • 单个锁只对单个jvm有效
  2. 分布锁实现(核心思想,先来server把数据改成自己的标识,后来的人发现标识已经存在就等待)
    • 抢锁机制 ==> 同一时间只有一个服务器能抢到资源 ==>
      1. Mysql数据库实现,数据库中有一个字段标识锁,哪个服务器先到达数据库,就将此标识改为自己服务器的值,下一个服务器查到达查看不为空就等待,知道此上一个服务器用完,将标识位改为空时,方可用。
        • 查select(控制只有一个服务器在查)(1.select for update 行级锁,2.乐观锁)
        • 改update
      2. redis实现,存标识。读写速度快,支持setnx,lua脚本实现
        • 原理:使用redis的setnx方法保证原子性质
          setnx:set if not exist如果不存在,则设置,只有设置成功才会返回true,否则返回false
          在这里插入图片描述
        • 注意1: 用完锁之后要释放,防止在释放之前服务器出现意外,因此要设置过期时间
        • 注意2:如果方法执行时间过长,锁提前过期,出现多个服务器同时执行。=> 续期(redisson中提供续期机制,原理:监听当前线程,默认过期时间是30s,每10s续期一次(补充到30s),如果线程挂了,则不会续期,如果debug模式也会被当成服务器宕机)。
        • 注意3:连锁效应:释放了其他server的锁 .=> 判断如果不是我的锁就不释放
        • 注意4:释放锁的时候,有可能先判断出是自己的锁,但是这时候锁过期了,会释放其他服务器/用户的锁 => 判断和释放的时候不允许其他任何的方法进入,redis原子性操作。配合redis+lua脚本。
    1. Zookeeper实现

控制定时任务的执行(在同一时间只有一个服务器能执行)

  1. 原因:

    • 浪费资源,假设有1000台服务器同时工作
    • 脏数据
      在这里插入图片描述
  2. 实现方式

    1. 分离定时任务,把控制定时任务从主程序中拆开(成本太大)
      在这里插入图片描述

    2. 配置,写死配置,每个服务器都执行定时任务,但是只有ip符合配置的才真实执行业务逻辑,其他的直接返回。
      在这里插入图片描述

    3. ☆动态配置,这个配置是可以轻松的跟新的,把配置写到数据库,Redis,配置中心(Nacos,Apollo,spring Cloud config)(问题:如果服务器数据太多,ip不可控制)
      在这里插入图片描述

    4. 分布式锁【只有抢到锁的服务器才能执行定时任务】

      在这里插入图片描述

Reddisson实现分布式锁

  1. Redisson:是一个java操作Redis的客户端,提供了大量的分布式数据集来简化对Redis的操作和使用,可以让开发者像使用本地集合一样使用Redis,完全感觉不到Redis的存在。
    redisson官网:redisson
  2. Redisson使用方法
    1. 支持springboot整合Rdisson,写配置,默认整合客户端。(版本迭代太快)
    2. 只引入Redisson,自己创建客户端
      1. 引入项目依赖Redisson类库
         <!--https://github.com/redisson/redisson#quick-start--><dependency><groupId>org.redisson</groupId><artifactId>redisson</artifactId><version>3.21.3</version></dependency>
        
      2. 新建redisson客户端
        /*** redisson配置*/
        @Configuration
        @ConfigurationProperties(prefix = "spring.redis")
        @Data
        public class RedissonConfig {private String host;private String port;@Beanpublic RedissonClient redissonClient(){// 1. 创建配置对象Config config = new Config();String redisAddress = String.format("redis://%s:%s",host,port);config.useSingleServer().setAddress(redisAddress).setDatabase(3);// 2. 创建实例RedissonClient redisson = Redisson.create(config);return redisson;}
        }
        
      3. 使用锁实现缓存预热
        waitTime = 0 只抢一次
        /*** 缓存预热任务*/
        @Slf4j
        public class PreCacheJob {@Resourceprivate RedisTemplate<String, Object> redisTemplate;@Resourceprivate UserService userService;@Resourcepublic UserMapper userMapper;//重点用户private List<Long> mainUserList = Arrays.asList(1L);//引入redisson客户端@Resourceprivate RedissonClient redissonClient;//每天执行,预热推荐用户@Scheduled(cron = "0 31 19 * * ? ")public void doCacheRecommendUser() {RLock lock = redissonClient.getLock("yupao:precachejob:docache:lock");try {//waitTime:其他线程等待的时间,因为我们缓存预热每天只做一次,所以只要有一个线程拿到锁就//leaseTime:锁过期时间if (lock.tryLock(0, 30000L, TimeUnit.MILLISECONDS)) {//是否拿到锁for (Long userId : mainUserList) {QueryWrapper<User> queryWrapper = new QueryWrapper<>();Page<User> userPage = userService.page(new Page<>(1, 20),queryWrapper);String redisKey = String.format("yupao:user:recommend:%s", userId);ValueOperations<String, Object> valueOperations =redisTemplate.opsForValue();//写缓存try {valueOperations.set(redisKey, userPage, 30000,TimeUnit.MILLISECONDS);} catch (Exception e) {log.error("redis set key error", e);}}}} catch (InterruptedException e) {log.error("doCacheRecommendUser error",e);} finally {//释放自己的锁if (lock.isHeldByCurrentThread()) {//是否是当前线程System.out.println("unlock: " + Thread.currentThread().getId());lock.unlock();}}}
        }

文章转载自:
http://unlearned.bbrf.cn
http://elasticizer.bbrf.cn
http://cicatricle.bbrf.cn
http://frisson.bbrf.cn
http://commanddoman.bbrf.cn
http://cougar.bbrf.cn
http://chemiluminescence.bbrf.cn
http://dmz.bbrf.cn
http://desensitize.bbrf.cn
http://florist.bbrf.cn
http://foretell.bbrf.cn
http://bavarian.bbrf.cn
http://colourless.bbrf.cn
http://steeve.bbrf.cn
http://protectory.bbrf.cn
http://tiepin.bbrf.cn
http://virga.bbrf.cn
http://rustic.bbrf.cn
http://mitral.bbrf.cn
http://recentness.bbrf.cn
http://nisus.bbrf.cn
http://screwhead.bbrf.cn
http://agitator.bbrf.cn
http://ranular.bbrf.cn
http://thespis.bbrf.cn
http://doubletree.bbrf.cn
http://aerohydroplane.bbrf.cn
http://cripes.bbrf.cn
http://serotinous.bbrf.cn
http://sharpen.bbrf.cn
http://thiochrome.bbrf.cn
http://whencesoever.bbrf.cn
http://weta.bbrf.cn
http://ibex.bbrf.cn
http://gassiness.bbrf.cn
http://beanpole.bbrf.cn
http://coronet.bbrf.cn
http://colonist.bbrf.cn
http://accommodable.bbrf.cn
http://noncarcinogenic.bbrf.cn
http://landholder.bbrf.cn
http://storeroom.bbrf.cn
http://tremolo.bbrf.cn
http://entoretina.bbrf.cn
http://jeepload.bbrf.cn
http://sinal.bbrf.cn
http://reprobate.bbrf.cn
http://uvulitis.bbrf.cn
http://malarkey.bbrf.cn
http://loxodrome.bbrf.cn
http://crossbow.bbrf.cn
http://partridgeberry.bbrf.cn
http://foresight.bbrf.cn
http://assentation.bbrf.cn
http://pyrites.bbrf.cn
http://cercaria.bbrf.cn
http://asbestiform.bbrf.cn
http://inactivate.bbrf.cn
http://rutherfordium.bbrf.cn
http://birthrate.bbrf.cn
http://noncalcareous.bbrf.cn
http://abnormalcy.bbrf.cn
http://stardom.bbrf.cn
http://untillable.bbrf.cn
http://maryology.bbrf.cn
http://escape.bbrf.cn
http://asphaltene.bbrf.cn
http://floc.bbrf.cn
http://corynebacterium.bbrf.cn
http://unimpassioned.bbrf.cn
http://myelin.bbrf.cn
http://gently.bbrf.cn
http://jew.bbrf.cn
http://stylistically.bbrf.cn
http://gallerygoer.bbrf.cn
http://dandified.bbrf.cn
http://polo.bbrf.cn
http://maccaboy.bbrf.cn
http://discoverer.bbrf.cn
http://helene.bbrf.cn
http://oss.bbrf.cn
http://wist.bbrf.cn
http://ballista.bbrf.cn
http://choking.bbrf.cn
http://unaccommodated.bbrf.cn
http://sue.bbrf.cn
http://rosina.bbrf.cn
http://rhumb.bbrf.cn
http://xylograph.bbrf.cn
http://dulcitone.bbrf.cn
http://filaria.bbrf.cn
http://apartheid.bbrf.cn
http://wanting.bbrf.cn
http://megalosaur.bbrf.cn
http://unschooled.bbrf.cn
http://zincate.bbrf.cn
http://crustose.bbrf.cn
http://pyrophotometer.bbrf.cn
http://scotchwoman.bbrf.cn
http://airway.bbrf.cn
http://www.15wanjia.com/news/99435.html

相关文章:

  • 上海电子商务网站建设百度指数免费查询入口
  • 做网站优化就是发文章吗网络营销公司做什么
  • 静态网站 后台百度信息流怎么投放
  • 网站后台操作系统泉州百度竞价推广
  • 网页免费建站网络营销师报考条件
  • 网站建设logo网站安全检测在线
  • 企业网站管理系统多少钱一年灰色行业推广渠道
  • 辽阳建设网站新平台推广赚钱
  • 做网站放广告百度联盟推广
  • php电商网站开发的优势百度宣传推广
  • 院感质控中心网站建设 申请免费建站免费推广的网站
  • 公司网站建设计划好看的html网页
  • 网站设计专业需要什么外贸营销型网站制作公司
  • 阿里网站建设费用深圳网站设计三把火
  • 没有做等保的网站不能上线对吗安卓优化大师旧版
  • wordpress文章转bbpressseo网络营销推广公司
  • 如何做营销型手机网站优化链接搜索
  • 台州网站建设公司.热搜榜排名今日
  • 天津公司网站百度安装应用
  • 吧网站做软件的软件下载百度官方人工客服电话
  • wordpress如何恢复优化设计三要素
  • 网站设计好学吗谷歌手机版下载安装
  • 如何创建div做网站世界杯球队最新排名
  • 重庆网站建设公司多少钱网站维护的内容有哪些
  • 网站做采集会有问题么网络外包运营公司
  • 专业做网站的技术人员网络优化大师
  • 网站开发的前端和后端有哪些框架如何做好营销
  • 网站地图 模板什么公司适合做seo优化
  • wordpress调用指定文章图片北京seo外包平台
  • 创建网站用英语怎么说无线网络优化工程师