预估秒杀人数,设定自动释放锁时间

This commit is contained in:
小柒2012
2018-05-19 18:40:46 +08:00
parent 89081e8f36
commit 9d1ca62ab3
3 changed files with 7 additions and 7 deletions

View File

@@ -26,8 +26,8 @@ public class SeckillDistributedServiceImpl implements ISeckillDistributedService
public Result startSeckilRedisLock(long seckillId,long userId) {
boolean res=false;
try {
//尝试获取锁,最多等待10秒,上锁以后10秒自动解锁实际项目中推荐这种以防出现死锁
res = RedissLockUtil.tryLock(seckillId+"", TimeUnit.SECONDS, 20, 10);
//尝试获取锁,最多等待3秒,上锁以后20秒自动解锁实际项目中推荐这种以防出现死锁、这里根据预估秒杀人数,设定自动释放锁时间
res = RedissLockUtil.tryLock(seckillId+"", TimeUnit.SECONDS, 3, 20);
String nativeSql = "SELECT number FROM seckill WHERE seckill_id=?";
Object object = dynamicQuery.nativeQueryObject(nativeSql, new Object[]{seckillId});
Long number = ((Number) object).longValue();

View File

@@ -56,7 +56,7 @@ public class SeckillDistributedController {
executor.execute(task);
}
try {
Thread.sleep(10000);
Thread.sleep(15000);
Long seckillCount = seckillService.getSeckillCount(seckillId);
LOGGER.info("一共秒杀出{}件商品",seckillCount);
} catch (InterruptedException e) {