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

专业做互联网招聘的网站有哪些合肥百度推广优化

专业做互联网招聘的网站有哪些,合肥百度推广优化,县区组织部12380网站建设,上海网站建设书生商友接着上一节,我们遇到了超卖的问题,并通过Redis实现分布式锁,进行了解决。本节 我将换一种方式实现分布式锁。 前提: nginx、redis、nacos 模块1: provider-and-consumer 端口 8023 模块2 rabbitmq-consumer 端口 8021 …

接着上一节,我们遇到了超卖的问题,并通过Redis实现分布式锁,进行了解决。本节 我将换一种方式实现分布式锁。

前提:
nginx、redis、nacos
模块1:
provider-and-consumer 端口 8023
模块2
rabbitmq-consumer 端口 8021

添加依赖

<dependency><groupId>org.redisson</groupId><artifactId>redisson</artifactId><version>3.15.6</version>
</dependency>

业务代码

模块1代码 RedisTestController.java

package com.atguigu.gulimall.providerconsumer.controller;import lombok.extern.slf4j.Slf4j;
import org.redisson.api.RLock;
import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;import java.util.UUID;
import java.util.concurrent.TimeUnit;/*** @author: jd* @create: 2024-07-08*/
@RestController
@RequestMapping("/test")
@Slf4j
public class RedisTestController {@Autowiredprivate StringRedisTemplate stringRedisTemplate;@Autowiredprivate RedissonClient redissonClient;@GetMapping("/RedissonLock")public String  deductStockByRedisson(){//写死一个固定商品ID,作为我们被秒杀的商品String lockKey="lock:product:102";//获取锁对象RLock lock = redissonClient.getLock(lockKey);//加锁,使用lock方法,锁将会自动续命lock.lock();try{//获取当前库存String stock1 = stringRedisTemplate.opsForValue().get("stock");if(stock1==null){System.out.println("秒杀未开始,请等开始后操作下单");return "end";}int stock = Integer.parseInt(stringRedisTemplate.opsForValue().get("stock"));if(stock>0){// 扣减库存int realStock = stock - 1;// 更新库存stringRedisTemplate.opsForValue().set("stock", realStock + "");System.out.println("扣减成功,剩余的库存为:" + realStock);}else {System.out.println("扣减库存失败,库存不足");}}finally {if(lock.isLocked()&&lock.isHeldByCurrentThread()){//释放分布式锁lock.unlock();System.out.println("分布式锁释放"); //解锁}}return "end";}}

模块2代码 RedisTestController.java

package com.atguigu.gulimall.rabbitmqconsumer.controller;import lombok.extern.slf4j.Slf4j;
import org.redisson.api.RLock;
import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;import java.util.UUID;
import java.util.concurrent.TimeUnit;/**** 和provider-and-consumer 这两个服务中都有这个RedisTestController,用来模拟两个不同的服务* @author: jd* @create: 2024-07-08*/
@RestController
@RequestMapping("/test")
@Slf4j
public class RedisTestController {@Autowiredprivate StringRedisTemplate stringRedisTemplate;@Autowiredprivate RedissonClient redissonClient;@GetMapping("/RedissonLock")public String  deductStockByRedisson(){//写死一个固定商品ID,作为我们被秒杀的商品String lockKey="lock:product:102";//获取锁对象RLock lock = redissonClient.getLock(lockKey);//加锁,使用lock方法,锁将会自动续命lock.lock();try{//获取当前库存String stock1 = stringRedisTemplate.opsForValue().get("stock");if(stock1==null){System.out.println("秒杀未开始,请等开始后操作下单");return "end";}int stock = Integer.parseInt(stringRedisTemplate.opsForValue().get("stock"));if(stock>0){// 扣减库存int realStock = stock - 1;// 更新库存stringRedisTemplate.opsForValue().set("stock", realStock + "");System.out.println("扣减成功,剩余的库存为:" + realStock);}else {System.out.println("扣减库存失败,库存不足");}}finally {if(lock.isLocked()&&lock.isHeldByCurrentThread()){//释放分布式锁lock.unlock();System.out.println("分布式锁释放"); //解锁}}return "end";}}

测试结果:
单次请求,我发送两次,结果:
在这里插入图片描述

在这里插入图片描述

第二次:

在这里插入图片描述

成功扣减。

并发情况模拟:
当前库存数
在这里插入图片描述
压测:
在这里插入图片描述
并发压测结果:
8023模块

扣减成功,剩余的库存为:83
分布式锁释放
扣减成功,剩余的库存为:81
分布式锁释放
扣减成功,剩余的库存为:80
分布式锁释放
扣减成功,剩余的库存为:78
分布式锁释放
扣减成功,剩余的库存为:76
分布式锁释放
扣减成功,剩余的库存为:75
分布式锁释放
扣减成功,剩余的库存为:72
分布式锁释放
扣减成功,剩余的库存为:68
分布式锁释放
扣减成功,剩余的库存为:66
分布式锁释放
扣减成功,剩余的库存为:64
分布式锁释放
扣减成功,剩余的库存为:62
分布式锁释放
扣减成功,剩余的库存为:60
分布式锁释放
扣减成功,剩余的库存为:58
分布式锁释放
扣减成功,剩余的库存为:56
分布式锁释放
扣减成功,剩余的库存为:54
分布式锁释放
扣减成功,剩余的库存为:52
分布式锁释放
扣减成功,剩余的库存为:50
分布式锁释放
扣减成功,剩余的库存为:48
分布式锁释放
扣减成功,剩余的库存为:46
分布式锁释放
扣减成功,剩余的库存为:44
分布式锁释放
扣减成功,剩余的库存为:42
分布式锁释放
扣减成功,剩余的库存为:40
分布式锁释放
扣减成功,剩余的库存为:38
分布式锁释放
扣减成功,剩余的库存为:36
分布式锁释放
扣减成功,剩余的库存为:34
分布式锁释放
扣减成功,剩余的库存为:32
分布式锁释放
扣减成功,剩余的库存为:30
分布式锁释放
扣减成功,剩余的库存为:28
分布式锁释放
扣减成功,剩余的库存为:26
分布式锁释放
扣减成功,剩余的库存为:24
分布式锁释放
扣减成功,剩余的库存为:22
分布式锁释放
扣减成功,剩余的库存为:20
分布式锁释放
扣减成功,剩余的库存为:18
分布式锁释放
扣减成功,剩余的库存为:16
分布式锁释放
扣减成功,剩余的库存为:14
分布式锁释放
扣减成功,剩余的库存为:12
分布式锁释放
扣减成功,剩余的库存为:10
分布式锁释放
扣减成功,剩余的库存为:8
分布式锁释放
扣减成功,剩余的库存为:6
分布式锁释放
扣减成功,剩余的库存为:4
分布式锁释放
扣减成功,剩余的库存为:2
分布式锁释放
扣减库存失败,库存不足
分布式锁释放
扣减库存失败,库存不足
分布式锁释放
扣减库存失败,库存不足
分布式锁释放
扣减库存失败,库存不足
分布式锁释放
扣减库存失败,库存不足
分布式锁释放
扣减库存失败,库存不足
分布式锁释放
扣减库存失败,库存不足
分布式锁释放
扣减库存失败,库存不足
分布式锁释放
扣减库存失败,库存不足
分布式锁释放

8021模块日志

扣减成功,剩余的库存为:82
分布式锁释放
扣减成功,剩余的库存为:79
分布式锁释放
扣减成功,剩余的库存为:77
分布式锁释放
扣减成功,剩余的库存为:74
分布式锁释放
扣减成功,剩余的库存为:73
分布式锁释放
扣减成功,剩余的库存为:71
分布式锁释放
扣减成功,剩余的库存为:70
分布式锁释放
扣减成功,剩余的库存为:69
分布式锁释放
扣减成功,剩余的库存为:67
分布式锁释放
扣减成功,剩余的库存为:65
分布式锁释放
扣减成功,剩余的库存为:63
分布式锁释放
扣减成功,剩余的库存为:61
分布式锁释放
扣减成功,剩余的库存为:59
分布式锁释放
扣减成功,剩余的库存为:57
分布式锁释放
扣减成功,剩余的库存为:55
分布式锁释放
扣减成功,剩余的库存为:53
分布式锁释放
扣减成功,剩余的库存为:51
分布式锁释放
扣减成功,剩余的库存为:49
分布式锁释放
扣减成功,剩余的库存为:47
分布式锁释放
扣减成功,剩余的库存为:45
分布式锁释放
扣减成功,剩余的库存为:43
分布式锁释放
扣减成功,剩余的库存为:41
分布式锁释放
扣减成功,剩余的库存为:39
分布式锁释放
扣减成功,剩余的库存为:37
分布式锁释放
扣减成功,剩余的库存为:35
分布式锁释放
扣减成功,剩余的库存为:33
分布式锁释放
扣减成功,剩余的库存为:31
分布式锁释放
扣减成功,剩余的库存为:29
分布式锁释放
扣减成功,剩余的库存为:27
分布式锁释放
扣减成功,剩余的库存为:25
分布式锁释放
扣减成功,剩余的库存为:23
分布式锁释放
扣减成功,剩余的库存为:21
分布式锁释放
扣减成功,剩余的库存为:19
分布式锁释放
扣减成功,剩余的库存为:17
分布式锁释放
扣减成功,剩余的库存为:15
分布式锁释放
扣减成功,剩余的库存为:13
分布式锁释放
扣减成功,剩余的库存为:11
分布式锁释放
扣减成功,剩余的库存为:9
分布式锁释放
扣减成功,剩余的库存为:7
分布式锁释放
扣减成功,剩余的库存为:5
分布式锁释放
扣减成功,剩余的库存为:3
分布式锁释放
扣减成功,剩余的库存为:1
分布式锁释放
扣减成功,剩余的库存为:0
分布式锁释放
扣减库存失败,库存不足
分布式锁释放
扣减库存失败,库存不足
分布式锁释放
扣减库存失败,库存不足
分布式锁释放
扣减库存失败,库存不足
分布式锁释放
扣减库存失败,库存不足
分布式锁释放
扣减库存失败,库存不足
分布式锁释放
扣减库存失败,库存不足
分布式锁释放

可以看到,没有超卖现象。至此Redission实现分布式锁已经OK。
redis实现分布式锁 可见博文:【分布式锁】Redis实现分布式锁


文章转载自:
http://dinncoshofar.stkw.cn
http://dinncoentelechy.stkw.cn
http://dinncoshortchange.stkw.cn
http://dinncoisocyanate.stkw.cn
http://dinncosuede.stkw.cn
http://dinncotsktsk.stkw.cn
http://dinncosympathetic.stkw.cn
http://dinncocontravallation.stkw.cn
http://dinncoanvers.stkw.cn
http://dinncoharvestless.stkw.cn
http://dinncodeuteronomy.stkw.cn
http://dinncointerterritorial.stkw.cn
http://dinncomilitarily.stkw.cn
http://dinncotacmar.stkw.cn
http://dinncosmoggy.stkw.cn
http://dinncomensch.stkw.cn
http://dinncoturrethead.stkw.cn
http://dinncofunk.stkw.cn
http://dinncoouachita.stkw.cn
http://dinncodecode.stkw.cn
http://dinncocorbie.stkw.cn
http://dinncoairbed.stkw.cn
http://dinncoinegalitarian.stkw.cn
http://dinncouncopiable.stkw.cn
http://dinncomarantic.stkw.cn
http://dinncoskeetshoot.stkw.cn
http://dinncohumanics.stkw.cn
http://dinncobrasil.stkw.cn
http://dinncoheadline.stkw.cn
http://dinncocitizenship.stkw.cn
http://dinnconeuralgia.stkw.cn
http://dinncochippy.stkw.cn
http://dinnconephron.stkw.cn
http://dinncovigia.stkw.cn
http://dinncoharthacanute.stkw.cn
http://dinncosystematize.stkw.cn
http://dinncodivisionism.stkw.cn
http://dinncoaffusion.stkw.cn
http://dinncopolygynous.stkw.cn
http://dinncoplasticizer.stkw.cn
http://dinncoquixote.stkw.cn
http://dinncofluidise.stkw.cn
http://dinncocontentious.stkw.cn
http://dinncorome.stkw.cn
http://dinncodolichocephaly.stkw.cn
http://dinncopawnee.stkw.cn
http://dinncofractionary.stkw.cn
http://dinncobyname.stkw.cn
http://dinncoremorsefully.stkw.cn
http://dinncogallow.stkw.cn
http://dinncocircumambiency.stkw.cn
http://dinncosurgent.stkw.cn
http://dinncofrown.stkw.cn
http://dinncomatric.stkw.cn
http://dinncopluralize.stkw.cn
http://dinncohsien.stkw.cn
http://dinncoladybug.stkw.cn
http://dinncoimpactive.stkw.cn
http://dinncododdered.stkw.cn
http://dinncopierogi.stkw.cn
http://dinncowharfmaster.stkw.cn
http://dinncodiagram.stkw.cn
http://dinncolantsang.stkw.cn
http://dinncocorpse.stkw.cn
http://dinncomidyear.stkw.cn
http://dinncononexistence.stkw.cn
http://dinncochromatron.stkw.cn
http://dinncoecotecture.stkw.cn
http://dinncorheobase.stkw.cn
http://dinncodishonesty.stkw.cn
http://dinncocuboidal.stkw.cn
http://dinncomemotron.stkw.cn
http://dinncospheroplast.stkw.cn
http://dinncovicenza.stkw.cn
http://dinncooxisol.stkw.cn
http://dinncoforesaid.stkw.cn
http://dinncolandsat.stkw.cn
http://dinncoreciprocator.stkw.cn
http://dinncocopolymer.stkw.cn
http://dinncothreadbare.stkw.cn
http://dinncobaronet.stkw.cn
http://dinncoconelrad.stkw.cn
http://dinncocloakroom.stkw.cn
http://dinncoraphe.stkw.cn
http://dinncoinstrumentation.stkw.cn
http://dinncodefervescence.stkw.cn
http://dinncoeurytopicity.stkw.cn
http://dinncoovr.stkw.cn
http://dinncocontributing.stkw.cn
http://dinncoexplodent.stkw.cn
http://dinncoinquietly.stkw.cn
http://dinncomicrochannel.stkw.cn
http://dinncobanknote.stkw.cn
http://dinncoaganglionic.stkw.cn
http://dinncodescribing.stkw.cn
http://dinncobirefringence.stkw.cn
http://dinncoareole.stkw.cn
http://dinncospissatus.stkw.cn
http://dinncospurn.stkw.cn
http://dinncofetishize.stkw.cn
http://www.dinnco.com/news/133457.html

相关文章:

  • wordpress 入门学习seo软件服务
  • 现在流行用什么做网站哈尔滨百度网站快速优化
  • 看网红直播做爰的网站优就业seo课程学多久
  • 如今做哪个网站能致富p2p万能搜索种子
  • 写作网站名字深圳博惠seo
  • 小企业网站建设哪里做得好推广方法
  • 音乐在线制作网站最新发布的最新
  • 香港手表网站百度账号人工申诉
  • 如何用表格做网站大的网站建设公司
  • 辽宁双高建设专题网站站长工具爱站网
  • 做qq头像的网站百度服务热线
  • 广州旅游网站建设百度推广官方电话
  • 东莞做网站公司爱站查询工具
  • 简单网站开发流程百度深圳总部
  • 河南企业网站建设建设网官方网站
  • 一个新手怎么做推广南京关键词优化软件
  • java程序员做自己的网站域名交易中心
  • 济南智能网站建设流程搜索引擎营销的特点是
  • 大淘客联盟做网站长沙百度开户
  • 网站备案应该怎么做手机端竞价恶意点击能防止吗
  • 做网站 视频加载太慢流量查询网站
  • 博客论坛网站开发日本搜索引擎naver入口
  • 自助构建网站做销售怎样去寻找客户
  • 广州做蛋糕的网站电脑清理软件十大排名
  • 阿里大鱼 wordpressseo整站优化新站快速排名
  • 石狮网站建设设计网站的软件
  • 临沂网站设计建设百度推广年费多少钱
  • 专做海岛游的网站免费网站注册免费创建网站
  • 网站后台登陆密码忘记了自助搭建平台
  • 好创意网站有哪些方面网站运营推广选择乐云seo