From 5af10f175689549ca44b74e9fc1c7ee0ec92c2d7 Mon Sep 17 00:00:00 2001
From: yujian <yujian@163.com>
Date: 星期二, 21 四月 2020 14:26:38 +0800
Subject: [PATCH] 后台改造
---
fanli/src/main/java/com/yeshi/fanli/aspect/RequestSerializableAspect.java | 40 ++++++++++++++++++++--------------------
1 files changed, 20 insertions(+), 20 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 a2d5d62..ca188f2 100644
--- a/fanli/src/main/java/com/yeshi/fanli/aspect/RequestSerializableAspect.java
+++ b/fanli/src/main/java/com/yeshi/fanli/aspect/RequestSerializableAspect.java
@@ -1,6 +1,5 @@
package com.yeshi.fanli.aspect;
-import java.io.IOException;
import java.io.PrintWriter;
import java.lang.reflect.Method;
import java.util.HashMap;
@@ -30,6 +29,7 @@
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
+import redis.clients.jedis.params.SetParams;
@Component
@Aspect
@@ -62,7 +62,7 @@
}
@Around("execution(public * com.yeshi.fanli.controller.client.*.*.*(..))")
- public Object requestSerializable(ProceedingJoinPoint joinPoint) throws IOException {
+ public Object requestSerializable(ProceedingJoinPoint joinPoint) throws Throwable {
Signature signature = joinPoint.getSignature();
MethodSignature methodSignature = (MethodSignature) signature;
Method targetMethod = methodSignature.getMethod();
@@ -92,52 +92,49 @@
if (!StringUtil.isNullOrEmpty(cacheKey)) {
cacheKey = joinPoint.getTarget().getClass().getName() + "." + targetMethod.getName() + "-"
+ cacheKey;
+ String cacheAlias = cacheKey;
cacheKey = "rs-" + StringUtil.Md5(cacheKey);
// jiedis鍘熷瓙鎬у仛鎷︽埅
Jedis jedis = jedisPool.getResource();
+ long threadId = Thread.currentThread().getId();
try {
- Constant.waitingThreadSet.add(Thread.currentThread().getId());
- long result = 0;
+ Constant.waitingThreadSet.add(threadId);
+ 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) {
e.printStackTrace();
}
- if (System.currentTimeMillis() - startTime > 1000 * 60L) {
+ if (System.currentTimeMillis() - startTime > 1000 * 30L) {
Constant.waitingThreadSet.remove(Thread.currentThread().getId());
out.print(JsonUtil.loadFalseResult("杩炴帴瓒呮椂"));
return null;
}
+ } else {
+ break;
}
}
- if (result > 0) {
+ if (!StringUtil.isNullOrEmpty(result)) {
try {
return joinPoint.proceed();
- } catch (Throwable e) {
- e.printStackTrace();
- LogHelper.errorDetailInfo(e);
} finally {
jedis.del(cacheKey);
Constant.waitingThreadSet.remove(Thread.currentThread().getId());
}
}
} finally {
- jedisPool.returnResource(jedis);
+ jedis.close();
}
}
} catch (Exception e) {// 鍘熷瓙鎬т繚鎶ゅ嚭閿�
- try {
- return joinPoint.proceed();
- } catch (Throwable e1) {
- e.printStackTrace();
- LogHelper.errorDetailInfo(e1);
- }
+ return joinPoint.proceed();
}
}
@@ -151,7 +148,10 @@
return joinPoint.proceed();
} catch (Throwable e) {
e.printStackTrace();
- LogHelper.errorDetailInfo(e);
+ if (!Constant.IS_TEST)
+ LogHelper.errorDetailInfo(e);
+ else
+ throw e;
} finally {
}
return null;
--
Gitblit v1.8.0