mirror of
https://gitee.com/52itstyle/spring-boot-seckill.git
synced 2025-12-30 10:22:26 +00:00
乐观锁、可以自定义抢购数量、如果配置的抢购人数比较少、比如120:100(人数:商品) 会出现少买的情况
This commit is contained in:
7
pom.xml
7
pom.xml
@@ -71,7 +71,7 @@
|
||||
<artifactId>springfox-swagger-ui</artifactId>
|
||||
<version>2.7.0</version>
|
||||
</dependency>
|
||||
<!-- Redisson实现分布式锁 -->
|
||||
<!-- Redisson 实现分布式锁 -->
|
||||
<dependency>
|
||||
<groupId>org.redisson</groupId>
|
||||
<artifactId>redisson</artifactId>
|
||||
@@ -82,7 +82,7 @@
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
<version>3.7</version>
|
||||
</dependency>
|
||||
<!--kafka支持-->
|
||||
<!--kafka 支持-->
|
||||
<dependency>
|
||||
<groupId>org.springframework.kafka</groupId>
|
||||
<artifactId>spring-kafka</artifactId>
|
||||
@@ -130,8 +130,7 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
<version>3.0.0</version>
|
||||
</plugin>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
|
||||
@@ -17,7 +17,7 @@ import com.google.common.util.concurrent.RateLimiter;
|
||||
@Scope
|
||||
@Aspect
|
||||
public class LimitAspect {
|
||||
////每秒只发出5个令牌,此处是单进程服务的限流
|
||||
////每秒只发出5个令牌,此处是单进程服务的限流,内部采用令牌捅算法实现
|
||||
private static RateLimiter rateLimiter = RateLimiter.create(5.0);
|
||||
|
||||
//Service层切点 限流
|
||||
|
||||
@@ -179,7 +179,9 @@ public class SeckillController {
|
||||
Runnable task = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Result result = seckillService.startSeckilDBOCC(killId, userId,4);
|
||||
//这里使用的乐观锁、可以自定义抢购数量、如果配置的抢购人数比较少、比如120:100(人数:商品) 会出现少买的情况
|
||||
//用户同时进入会出现更新失败的情况
|
||||
Result result = seckillService.startSeckilDBOCC(killId, userId,1);
|
||||
LOGGER.info("用户:{}{}",userId,result.get("msg"));
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user