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/RequestSerializableServiceAspect.java |   16 +++++++---------
 1 files changed, 7 insertions(+), 9 deletions(-)

diff --git a/fanli/src/main/java/com/yeshi/fanli/aspect/RequestSerializableServiceAspect.java b/fanli/src/main/java/com/yeshi/fanli/aspect/RequestSerializableServiceAspect.java
index caef6ed..cd36493 100644
--- a/fanli/src/main/java/com/yeshi/fanli/aspect/RequestSerializableServiceAspect.java
+++ b/fanli/src/main/java/com/yeshi/fanli/aspect/RequestSerializableServiceAspect.java
@@ -24,6 +24,7 @@
 
 import redis.clients.jedis.Jedis;
 import redis.clients.jedis.JedisPool;
+import redis.clients.jedis.params.SetParams;
 
 @Component
 @Aspect
@@ -70,12 +71,12 @@
 						Jedis jedis = jedisPool.getResource();
 						try {
 							Constant.waitingThreadSet.add(Thread.currentThread().getId());
-							long result = 0;
+							String result = null;
 							long startTime = System.currentTimeMillis();
 							// 绛夊緟鍝嶅簲
-							while (result <= 0) {
-								result = jedis.setnx(cacheKey, "1");
-								if (result <= 0) {
+							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) {
@@ -85,13 +86,10 @@
 										Constant.waitingThreadSet.remove(Thread.currentThread().getId());
 										return null;
 									}
-								} else {
-									// 璁剧疆30绉掑鐞嗘椂闂�
-									jedis.expire(cacheKey, 30);
 								}
 							}
 
-							if (result > 0) {
+							if (!StringUtil.isNullOrEmpty(result)) {
 								try {
 									return joinPoint.proceed();
 								} catch (Throwable e) {
@@ -103,7 +101,7 @@
 								}
 							}
 						} finally {
-							jedisPool.returnResource(jedis);
+							jedis.close();
 						}
 					}
 				} catch (Exception e) {// 鍘熷瓙鎬т繚鎶ゅ嚭閿�

--
Gitblit v1.8.0