From 486e22c57ca8a1e2dc6877b539e2f3add67250f1 Mon Sep 17 00:00:00 2001 From: admin <weikou2014> Date: 星期六, 23 十一月 2019 18:28:00 +0800 Subject: [PATCH] 冲突解决 --- fanli/src/main/java/com/yeshi/fanli/aspect/RequestSerializableAspect.java | 23 ++++++++--------------- 1 files changed, 8 insertions(+), 15 deletions(-) diff --git a/fanli/src/main/java/com/yeshi/fanli/aspect/RequestSerializableAspect.java b/fanli/src/main/java/com/yeshi/fanli/aspect/RequestSerializableAspect.java index a18292e..49a3058 100644 --- a/fanli/src/main/java/com/yeshi/fanli/aspect/RequestSerializableAspect.java +++ b/fanli/src/main/java/com/yeshi/fanli/aspect/RequestSerializableAspect.java @@ -30,6 +30,7 @@ import redis.clients.jedis.Jedis; import redis.clients.jedis.JedisPool; +import redis.clients.jedis.params.SetParams; @Component @Aspect @@ -97,18 +98,15 @@ // jiedis鍘熷瓙鎬у仛鎷︽埅 Jedis jedis = jedisPool.getResource(); long threadId= Thread.currentThread().getId(); - LogHelper.test("杩涘叆鎷︽埅:"+cacheKey+"-"+threadId); try { Constant.waitingThreadSet.add(threadId); - long result = 0; + String result = null; long startTime = System.currentTimeMillis(); // 绛夊緟鍝嶅簲 - while (result <= 0) { - result = jedis.setnx(cacheKey, "1"); - LogHelper.error("瑙﹀彂骞跺彂閿�:" + cacheAlias); - LogHelper.error("redis閿�:" + cacheKey); - if (result <= 0) { - LogHelper.test("绛夊緟:"+threadId); + while (StringUtil.isNullOrEmpty(result)) { + + result = jedis.set(cacheKey, "1", new SetParams().nx().ex(30)); + if (StringUtil.isNullOrEmpty(result)) { try { Thread.sleep(50); } catch (InterruptedException e) { @@ -120,28 +118,23 @@ return null; } } else { - // 璁剧疆30绉掑鐞嗘椂闂� - jedis.expire(cacheKey, 30); - LogHelper.test("鑾峰彇鍒伴攣:"+threadId); break; } } - if (result > 0) { + if (!StringUtil.isNullOrEmpty(result)) { try { return joinPoint.proceed(); } catch (Throwable e) { e.printStackTrace(); LogHelper.errorDetailInfo(e); } finally { - LogHelper.test("鏂规硶鎵ц瀹屾瘯:"+threadId); jedis.del(cacheKey); Constant.waitingThreadSet.remove(Thread.currentThread().getId()); - LogHelper.test("閲婃斁閿�:"+threadId); } } } finally { - jedisPool.returnResource(jedis); + jedis.close(); } } } catch (Exception e) {// 鍘熷瓙鎬т繚鎶ゅ嚭閿� -- Gitblit v1.8.0