乐观锁、可以自定义抢购数量、如果配置的抢购人数比较少、比如120:100(人数:商品) 会出现少买的情况

This commit is contained in:
小柒2012
2018-06-07 09:09:15 +08:00
parent 678096a79e
commit 7f29035b9e
3 changed files with 7 additions and 6 deletions

View File

@@ -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>

View File

@@ -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层切点 限流

View File

@@ -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"));
}
};